Introduce wxGraphicsPenInfo class
This commit is contained in:
committed by
Vadim Zeitlin
parent
bc562289c6
commit
2305604565
@@ -132,6 +132,49 @@ protected:
|
||||
wxDECLARE_DYNAMIC_CLASS(wxGraphicsObject);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGraphicsPenInfo describes a wxGraphicsPen
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxGraphicsPenInfo : public wxPenInfo
|
||||
{
|
||||
public:
|
||||
wxGraphicsPenInfo()
|
||||
: wxPenInfo()
|
||||
{
|
||||
m_widthF = -1.0;
|
||||
}
|
||||
|
||||
explicit wxGraphicsPenInfo(const wxColour& colour, double widthF = 1.0, wxPenStyle style = wxPENSTYLE_SOLID)
|
||||
: wxPenInfo(colour, 0, style)
|
||||
{
|
||||
m_widthF = widthF;
|
||||
}
|
||||
|
||||
// Setters for the various attributes. All of them return the object itself
|
||||
// so that the calls to them could be chained.
|
||||
|
||||
wxGraphicsPenInfo& Colour(const wxColour& colour);
|
||||
|
||||
wxGraphicsPenInfo& Width(int width);
|
||||
|
||||
wxGraphicsPenInfo& Style(wxPenStyle style);
|
||||
wxGraphicsPenInfo& Stipple(const wxBitmap& stipple);
|
||||
wxGraphicsPenInfo& Dashes(int nb_dashes, const wxDash *dash);
|
||||
wxGraphicsPenInfo& Join(wxPenJoin join);
|
||||
wxGraphicsPenInfo& Cap(wxPenCap cap);
|
||||
|
||||
wxGraphicsPenInfo& WidthF(wxDouble widthF)
|
||||
{ m_widthF = widthF; return *this; }
|
||||
|
||||
// Accessors are mostly meant to be used by wxGraphicsPen itself.
|
||||
|
||||
wxDouble GetWidthF() const { return m_widthF; }
|
||||
|
||||
private:
|
||||
wxDouble m_widthF;
|
||||
};
|
||||
|
||||
class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject
|
||||
{
|
||||
public:
|
||||
|
@@ -114,6 +114,10 @@ public:
|
||||
int GetWidth() const { return m_width; }
|
||||
int GetDashes(wxDash **ptr) const { *ptr = m_dash; return m_nb_dashes; }
|
||||
|
||||
// Convenience
|
||||
|
||||
bool IsTransparent() const { return m_style == wxPENSTYLE_TRANSPARENT; }
|
||||
|
||||
private:
|
||||
void Init()
|
||||
{
|
||||
|
@@ -253,7 +253,7 @@ enum wxInterpolationQuality
|
||||
/** default interpolation, based on type of context, in general medium quality */
|
||||
wxINTERPOLATION_DEFAULT,
|
||||
/** no interpolation */
|
||||
wxINTERPOLATION_NONE,
|
||||
wxINTERPOLATION_NONE,
|
||||
/** fast interpolation, suited for interactivity */
|
||||
wxINTERPOLATION_FAST,
|
||||
/** better quality */
|
||||
@@ -331,7 +331,7 @@ public:
|
||||
wxImage ConvertToImage() const;
|
||||
|
||||
/**
|
||||
Return the pointer to the native bitmap data. (CGImageRef for Core Graphics,
|
||||
Return the pointer to the native bitmap data. (CGImageRef for Core Graphics,
|
||||
cairo_surface_t for Cairo, Bitmap* for GDI+.)
|
||||
|
||||
@since 2.9.4
|
||||
@@ -680,6 +680,11 @@ public:
|
||||
*/
|
||||
virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
|
||||
|
||||
/**
|
||||
Creates a native pen from a wxGraphicsPenInfo.
|
||||
*/
|
||||
virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) const;
|
||||
|
||||
/**
|
||||
Sets the pen used for stroking.
|
||||
*/
|
||||
@@ -1527,6 +1532,46 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@class wxGraphicsPenInfo
|
||||
|
||||
This class is a helper used for wxGraphicsPen creation using named parameter
|
||||
idiom: it allows to specify various wxGraphicsPen attributes using the chained
|
||||
calls to its clearly named methods instead of passing them in the fixed
|
||||
order to wxGraphicsPen constructors.
|
||||
|
||||
@since 3.1.0
|
||||
*/
|
||||
class wxGraphicsPenInfo : public wxPenInfo
|
||||
{
|
||||
public:
|
||||
|
||||
wxGraphicsPenInfo();
|
||||
|
||||
explicit wxGraphicsPenInfo(const wxColour& colour, double widthF = 1.0, wxPenStyle style = wxPENSTYLE_SOLID);
|
||||
|
||||
wxGraphicsPenInfo& ();
|
||||
|
||||
wxGraphicsPenInfo& Colour(const wxColour& col);
|
||||
|
||||
wxGraphicsPenInfo& Width(int width);
|
||||
|
||||
wxGraphicsPenInfo& WidthF(wxDouble widthF);
|
||||
|
||||
wxGraphicsPenInfo& Style(wxPenStyle style);
|
||||
|
||||
wxGraphicsPenInfo& Style(wxPenStyle style);
|
||||
|
||||
wxGraphicsPenInfo& Stipple(const wxBitmap& stipple);
|
||||
|
||||
wxGraphicsPenInfo& Dashes(int nb_dashes, const wxDash *dash);
|
||||
|
||||
wxGraphicsPenInfo& Join(wxPenJoin join);
|
||||
|
||||
wxGraphicsPenInfo& Cap(wxPenCap cap);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@class wxGraphicsPen
|
||||
|
@@ -116,7 +116,7 @@ public:
|
||||
|
||||
wxPenInfo();
|
||||
|
||||
explicit wxPen(const wxColour& colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);
|
||||
explicit wxPenInfo(const wxColour& colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);
|
||||
|
||||
wxPenInfo& ();
|
||||
|
||||
|
@@ -285,9 +285,11 @@ class WXDLLIMPEXP_CORE wxCairoPenData : public wxCairoPenBrushBaseData
|
||||
{
|
||||
public:
|
||||
wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen );
|
||||
wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info );
|
||||
~wxCairoPenData();
|
||||
|
||||
void Init();
|
||||
void InitFromPenInfo( const wxGraphicsPenInfo& info );
|
||||
|
||||
virtual void Apply( wxGraphicsContext* context ) wxOVERRIDE;
|
||||
virtual wxDouble GetWidth() { return m_width; }
|
||||
@@ -735,13 +737,36 @@ void wxCairoPenData::Init()
|
||||
|
||||
wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen )
|
||||
: wxCairoPenBrushBaseData(renderer, pen.GetColour(), pen.IsTransparent())
|
||||
{
|
||||
wxDash *dashes;
|
||||
int nb_dashes = pen.GetDashes(&dashes);
|
||||
InitFromPenInfo(wxGraphicsPenInfo()
|
||||
.Colour(pen.GetColour())
|
||||
.Width(pen.GetWidth())
|
||||
.Style(pen.GetStyle())
|
||||
.Stipple(*pen.GetStipple())
|
||||
.Dashes(nb_dashes, dashes)
|
||||
.Join(pen.GetJoin())
|
||||
.Cap(pen.GetCap())
|
||||
);
|
||||
}
|
||||
|
||||
wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info )
|
||||
: wxCairoPenBrushBaseData(renderer, info.GetColour(), info.IsTransparent())
|
||||
{
|
||||
InitFromPenInfo(info);
|
||||
}
|
||||
|
||||
void wxCairoPenData::InitFromPenInfo( const wxGraphicsPenInfo &info )
|
||||
{
|
||||
Init();
|
||||
m_width = pen.GetWidth();
|
||||
m_width = info.GetWidthF();
|
||||
if (m_width < 0)
|
||||
m_width = info.GetWidth();
|
||||
if (m_width <= 0.0)
|
||||
m_width = 0.1;
|
||||
|
||||
switch ( pen.GetCap() )
|
||||
switch ( info.GetCap() )
|
||||
{
|
||||
case wxCAP_ROUND :
|
||||
m_cap = CAIRO_LINE_CAP_ROUND;
|
||||
@@ -760,7 +785,7 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen )
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( pen.GetJoin() )
|
||||
switch ( info.GetJoin() )
|
||||
{
|
||||
case wxJOIN_BEVEL :
|
||||
m_join = CAIRO_LINE_JOIN_BEVEL;
|
||||
@@ -797,7 +822,7 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen )
|
||||
9.0 , 6.0 , 3.0 , 3.0
|
||||
};
|
||||
|
||||
switch ( pen.GetStyle() )
|
||||
switch ( info.GetStyle() )
|
||||
{
|
||||
case wxPENSTYLE_SOLID :
|
||||
break;
|
||||
@@ -827,7 +852,7 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen )
|
||||
case wxPENSTYLE_USER_DASH :
|
||||
{
|
||||
wxDash *wxdashes ;
|
||||
m_count = pen.GetDashes( &wxdashes ) ;
|
||||
m_count = info.GetDashes( &wxdashes ) ;
|
||||
if ((wxdashes != NULL) && (m_count > 0))
|
||||
{
|
||||
m_userLengths = new double[m_count] ;
|
||||
@@ -848,14 +873,14 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen )
|
||||
case wxPENSTYLE_STIPPLE :
|
||||
case wxPENSTYLE_STIPPLE_MASK :
|
||||
case wxPENSTYLE_STIPPLE_MASK_OPAQUE :
|
||||
InitStipple(pen.GetStipple());
|
||||
InitStipple(((wxGraphicsPenInfo&) info).GetStipple());
|
||||
break;
|
||||
|
||||
default :
|
||||
if ( pen.GetStyle() >= wxPENSTYLE_FIRST_HATCH
|
||||
&& pen.GetStyle() <= wxPENSTYLE_LAST_HATCH )
|
||||
if ( info.GetStyle() >= wxPENSTYLE_FIRST_HATCH
|
||||
&& info.GetStyle() <= wxPENSTYLE_LAST_HATCH )
|
||||
{
|
||||
InitHatch(static_cast<wxHatchStyle>(pen.GetStyle()));
|
||||
InitHatch(static_cast<wxHatchStyle>(info.GetStyle()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2901,6 +2926,7 @@ public :
|
||||
|
||||
|
||||
virtual wxGraphicsPen CreatePen(const wxPen& pen) wxOVERRIDE ;
|
||||
virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) wxOVERRIDE ;
|
||||
|
||||
virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) wxOVERRIDE ;
|
||||
|
||||
@@ -3087,6 +3113,17 @@ wxGraphicsPen wxCairoRenderer::CreatePen(const wxPen& pen)
|
||||
return p;
|
||||
}
|
||||
|
||||
wxGraphicsPen wxCairoRenderer::CreatePen(const wxGraphicsPenInfo& info)
|
||||
{
|
||||
wxGraphicsPen p;
|
||||
ENSURE_LOADED_OR_RETURN(p);
|
||||
if (info.GetStyle() != wxPENSTYLE_TRANSPARENT)
|
||||
{
|
||||
p.SetRefData(new wxCairoPenData( this, info ));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
wxGraphicsBrush wxCairoRenderer::CreateBrush(const wxBrush& brush )
|
||||
{
|
||||
wxGraphicsBrush p;
|
||||
|
@@ -261,9 +261,11 @@ class wxGDIPlusPenData : public wxGraphicsObjectRefData
|
||||
{
|
||||
public:
|
||||
wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen );
|
||||
wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info );
|
||||
~wxGDIPlusPenData();
|
||||
|
||||
void Init();
|
||||
void InitFromPenInfo( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info );
|
||||
|
||||
virtual wxDouble GetWidth() { return m_width; }
|
||||
virtual Pen* GetGDIPlusPen() { return m_pen; }
|
||||
@@ -400,7 +402,7 @@ public:
|
||||
virtual bool SetAntialiasMode(wxAntialiasMode antialias) wxOVERRIDE;
|
||||
|
||||
virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation) wxOVERRIDE;
|
||||
|
||||
|
||||
virtual bool SetCompositionMode(wxCompositionMode op) wxOVERRIDE;
|
||||
|
||||
virtual void BeginLayer(wxDouble opacity) wxOVERRIDE;
|
||||
@@ -575,6 +577,8 @@ public :
|
||||
|
||||
virtual wxGraphicsPen CreatePen(const wxPen& pen) wxOVERRIDE;
|
||||
|
||||
virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& pen) wxOVERRIDE;
|
||||
|
||||
virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) wxOVERRIDE;
|
||||
|
||||
virtual wxGraphicsBrush
|
||||
@@ -645,16 +649,39 @@ void wxGDIPlusPenData::Init()
|
||||
|
||||
wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen )
|
||||
: wxGraphicsObjectRefData(renderer)
|
||||
{
|
||||
wxDash *dashes;
|
||||
int nb_dashes = pen.GetDashes(&dashes);
|
||||
InitFromPenInfo(renderer, wxGraphicsPenInfo()
|
||||
.Colour(pen.GetColour())
|
||||
.Width(pen.GetWidth())
|
||||
.Style(pen.GetStyle())
|
||||
.Stipple(*pen.GetStipple())
|
||||
.Dashes(nb_dashes, dashes)
|
||||
.Join(pen.GetJoin())
|
||||
.Cap(pen.GetCap())
|
||||
);
|
||||
}
|
||||
|
||||
wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info )
|
||||
: wxGraphicsObjectRefData(renderer)
|
||||
{
|
||||
InitFromPenInfo(renderer, info);
|
||||
}
|
||||
|
||||
void wxGDIPlusPenData::InitFromPenInfo( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info )
|
||||
{
|
||||
Init();
|
||||
m_width = pen.GetWidth();
|
||||
m_width = info.GetWidthF();
|
||||
if (m_info < 0.0)
|
||||
m_width = info.GetWidth();
|
||||
if (m_width <= 0.0)
|
||||
m_width = 0.1;
|
||||
|
||||
m_pen = new Pen(wxColourToColor(pen.GetColour()), m_width );
|
||||
m_pen = new Pen(wxColourToColor(info.GetColour()), m_width );
|
||||
|
||||
LineCap cap;
|
||||
switch ( pen.GetCap() )
|
||||
switch ( info.GetCap() )
|
||||
{
|
||||
case wxCAP_ROUND :
|
||||
cap = LineCapRound;
|
||||
@@ -675,7 +702,7 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p
|
||||
m_pen->SetLineCap(cap,cap, DashCapFlat);
|
||||
|
||||
LineJoin join;
|
||||
switch ( pen.GetJoin() )
|
||||
switch ( info.GetJoin() )
|
||||
{
|
||||
case wxJOIN_BEVEL :
|
||||
join = LineJoinBevel;
|
||||
@@ -699,7 +726,7 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p
|
||||
m_pen->SetDashStyle(DashStyleSolid);
|
||||
|
||||
DashStyle dashStyle = DashStyleSolid;
|
||||
switch ( pen.GetStyle() )
|
||||
switch ( info.GetStyle() )
|
||||
{
|
||||
case wxPENSTYLE_SOLID :
|
||||
break;
|
||||
@@ -723,7 +750,7 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p
|
||||
{
|
||||
dashStyle = DashStyleCustom;
|
||||
wxDash *dashes;
|
||||
int count = pen.GetDashes( &dashes );
|
||||
int count = info.GetDashes( &dashes );
|
||||
if ((dashes != NULL) && (count > 0))
|
||||
{
|
||||
REAL *userLengths = new REAL[count];
|
||||
@@ -738,7 +765,7 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p
|
||||
break;
|
||||
case wxPENSTYLE_STIPPLE :
|
||||
{
|
||||
wxBitmap* bmp = pen.GetStipple();
|
||||
wxBitmap* bmp = info.GetStipple();
|
||||
if ( bmp && bmp->IsOk() )
|
||||
{
|
||||
m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),
|
||||
@@ -755,11 +782,11 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p
|
||||
}
|
||||
break;
|
||||
default :
|
||||
if ( pen.GetStyle() >= wxPENSTYLE_FIRST_HATCH &&
|
||||
pen.GetStyle() <= wxPENSTYLE_LAST_HATCH )
|
||||
if ( info.GetStyle() >= wxPENSTYLE_FIRST_HATCH &&
|
||||
info.GetStyle() <= wxPENSTYLE_LAST_HATCH )
|
||||
{
|
||||
HatchStyle style;
|
||||
switch( pen.GetStyle() )
|
||||
switch( info.GetStyle() )
|
||||
{
|
||||
case wxPENSTYLE_BDIAGONAL_HATCH :
|
||||
style = HatchStyleBackwardDiagonal;
|
||||
@@ -785,7 +812,7 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p
|
||||
m_penBrush = new HatchBrush
|
||||
(
|
||||
style,
|
||||
wxColourToColor(pen.GetColour()),
|
||||
wxColourToColor(info.GetColour()),
|
||||
Color::Transparent
|
||||
);
|
||||
m_pen->SetBrush( m_penBrush );
|
||||
@@ -2047,7 +2074,7 @@ void wxGDIPlusContext::DoDrawText(const wxString& str,
|
||||
|
||||
wxGDIPlusFontData * const
|
||||
fontData = (wxGDIPlusFontData *)m_font.GetRefData();
|
||||
|
||||
|
||||
m_context->DrawString
|
||||
(
|
||||
str.wc_str(*wxConvUI), // string to draw, always Unicode
|
||||
@@ -2160,7 +2187,7 @@ bool wxGDIPlusContext::ShouldOffset() const
|
||||
{
|
||||
if ( !m_enableOffset )
|
||||
return false;
|
||||
|
||||
|
||||
int penwidth = 0 ;
|
||||
if ( !m_pen.IsNull() )
|
||||
{
|
||||
@@ -2461,6 +2488,19 @@ wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen)
|
||||
}
|
||||
}
|
||||
|
||||
wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxGraphicsPenInfo& info)
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen);
|
||||
if ( !info.GetStyle() == wxPENSTYLE_TRANSPARENT )
|
||||
return wxNullGraphicsPen;
|
||||
else
|
||||
{
|
||||
wxGraphicsPen p;
|
||||
p.SetRefData(new wxGDIPlusPenData( this, info ));
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush )
|
||||
{
|
||||
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
|
||||
|
@@ -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 )
|
||||
|
@@ -305,9 +305,11 @@ class wxMacCoreGraphicsPenData : public wxGraphicsObjectRefData
|
||||
{
|
||||
public:
|
||||
wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxPen &pen );
|
||||
wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo& info );
|
||||
~wxMacCoreGraphicsPenData();
|
||||
|
||||
void Init();
|
||||
void InitFromPenInfo( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo& info );
|
||||
virtual void Apply( wxGraphicsContext* context );
|
||||
virtual wxDouble GetWidth() { return m_width; }
|
||||
|
||||
@@ -331,17 +333,40 @@ protected :
|
||||
|
||||
wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxPen &pen ) :
|
||||
wxGraphicsObjectRefData( renderer )
|
||||
{
|
||||
wxDash *dashes;
|
||||
int nb_dashes = pen.GetDashes(&dashes);
|
||||
InitFromPenInfo(renderer, wxGraphicsPenInfo()
|
||||
.Colour(pen.GetColour())
|
||||
.Width(pen.GetWidth())
|
||||
.Style(pen.GetStyle())
|
||||
.Stipple(*pen.GetStipple())
|
||||
.Dashes(nb_dashes, dashes)
|
||||
.Join(pen.GetJoin())
|
||||
.Cap(pen.GetCap())
|
||||
);
|
||||
}
|
||||
|
||||
wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo& info ) :
|
||||
wxGraphicsObjectRefData( renderer )
|
||||
{
|
||||
InitFromPenInfo(renderer, info);
|
||||
}
|
||||
|
||||
void wxMacCoreGraphicsPenData::InitFromPenInfo( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo& info )
|
||||
{
|
||||
Init();
|
||||
|
||||
m_color.reset( wxMacCreateCGColor( pen.GetColour() ) ) ;
|
||||
m_color.reset( wxMacCreateCGColor( info.GetColour() ) ) ;
|
||||
|
||||
// TODO: * m_dc->m_scaleX
|
||||
m_width = pen.GetWidth();
|
||||
m_width = info.GetWidthF();
|
||||
if (m_width < 0.0)
|
||||
m_width = info.GetWidth();
|
||||
if (m_width <= 0.0)
|
||||
m_width = (CGFloat) 0.1;
|
||||
|
||||
switch ( pen.GetCap() )
|
||||
switch ( info.GetCap() )
|
||||
{
|
||||
case wxCAP_ROUND :
|
||||
m_cap = kCGLineCapRound;
|
||||
@@ -360,7 +385,7 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( pen.GetJoin() )
|
||||
switch ( info.GetJoin() )
|
||||
{
|
||||
case wxJOIN_BEVEL :
|
||||
m_join = kCGLineJoinBevel;
|
||||
@@ -386,7 +411,7 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer
|
||||
static const CGFloat dashed[] = { (CGFloat) 19.0 , (CGFloat) 9.0 };
|
||||
static const CGFloat dotted_dashed[] = { (CGFloat) 9.0 , (CGFloat) 6.0 , (CGFloat) 3.0 , (CGFloat) 3.0 };
|
||||
|
||||
switch ( pen.GetStyle() )
|
||||
switch ( info.GetStyle() )
|
||||
{
|
||||
case wxPENSTYLE_SOLID:
|
||||
break;
|
||||
@@ -415,7 +440,7 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer
|
||||
|
||||
case wxPENSTYLE_USER_DASH:
|
||||
wxDash *dashes;
|
||||
m_count = pen.GetDashes( &dashes );
|
||||
m_count = info.GetDashes( &dashes );
|
||||
if ((dashes != NULL) && (m_count > 0))
|
||||
{
|
||||
m_userLengths = new CGFloat[m_count];
|
||||
@@ -434,7 +459,7 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer
|
||||
|
||||
case wxPENSTYLE_STIPPLE:
|
||||
{
|
||||
wxBitmap* bmp = pen.GetStipple();
|
||||
wxBitmap* bmp = info.GetStipple();
|
||||
if ( bmp && bmp->IsOk() )
|
||||
{
|
||||
m_colorSpace.reset( CGColorSpaceCreatePattern( NULL ) );
|
||||
@@ -450,12 +475,12 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer
|
||||
{
|
||||
m_isPattern = true;
|
||||
m_colorSpace.reset( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
|
||||
m_pattern.reset( (CGPatternRef) *( new HatchPattern( pen.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
|
||||
m_pattern.reset( (CGPatternRef) *( new HatchPattern( info.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
|
||||
m_patternColorComponents = new CGFloat[4] ;
|
||||
m_patternColorComponents[0] = (CGFloat) (pen.GetColour().Red() / 255.0);
|
||||
m_patternColorComponents[1] = (CGFloat) (pen.GetColour().Green() / 255.0);
|
||||
m_patternColorComponents[2] = (CGFloat) (pen.GetColour().Blue() / 255.0);
|
||||
m_patternColorComponents[3] = (CGFloat) (pen.GetColour().Alpha() / 255.0);
|
||||
m_patternColorComponents[0] = (CGFloat) (info.GetColour().Red() / 255.0);
|
||||
m_patternColorComponents[1] = (CGFloat) (info.GetColour().Green() / 255.0);
|
||||
m_patternColorComponents[2] = (CGFloat) (info.GetColour().Blue() / 255.0);
|
||||
m_patternColorComponents[3] = (CGFloat) (info.GetColour().Alpha() / 255.0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2538,6 +2563,8 @@ public :
|
||||
|
||||
virtual wxGraphicsPen CreatePen(const wxPen& pen) wxOVERRIDE ;
|
||||
|
||||
virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) wxOVERRIDE ;
|
||||
|
||||
virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) wxOVERRIDE ;
|
||||
|
||||
virtual wxGraphicsBrush
|
||||
@@ -2717,6 +2744,18 @@ wxGraphicsPen wxMacCoreGraphicsRenderer::CreatePen(const wxPen& pen)
|
||||
}
|
||||
}
|
||||
|
||||
wxGraphicsPen wxMacCoreGraphicsRenderer::CreatePen(const wxGraphicsPenInfo& info)
|
||||
{
|
||||
if ( info.GetStyle() == wxPENSTYLE_TRANSPARENT )
|
||||
return wxNullGraphicsPen;
|
||||
else
|
||||
{
|
||||
wxGraphicsPen p;
|
||||
p.SetRefData(new wxMacCoreGraphicsPenData( this, info ));
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
wxGraphicsBrush wxMacCoreGraphicsRenderer::CreateBrush(const wxBrush& brush )
|
||||
{
|
||||
if ( !brush.IsOk() || brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT )
|
||||
|
Reference in New Issue
Block a user