Merge branch 'peninfo'

Add wxPenInfo and wxGraphicsPenInfo which allows to specify fractional
pen widths when using wxGraphicsContext.

Closes #17087.

Closes https://github.com/wxWidgets/wxWidgets/pull/472
This commit is contained in:
Vadim Zeitlin
2017-09-09 23:58:01 +02:00
34 changed files with 556 additions and 202 deletions

View File

@@ -35,6 +35,8 @@ public:
wxPen(const wxBitmap& stipple, int width);
wxPen(const wxPenInfo& info);
bool operator==(const wxPen& pen) const;
bool operator!=(const wxPen& pen) const { return !(*this == pen); }

View File

@@ -21,6 +21,7 @@
#include "wx/dynarray.h"
#include "wx/font.h"
#include "wx/image.h"
#include "wx/peninfobase.h"
#include "wx/vector.h"
enum wxAntialiasMode
@@ -132,6 +133,34 @@ protected:
wxDECLARE_DYNAMIC_CLASS(wxGraphicsObject);
};
// ----------------------------------------------------------------------------
// wxGraphicsPenInfo describes a wxGraphicsPen
// ----------------------------------------------------------------------------
class wxGraphicsPenInfo : public wxPenInfoBase<wxGraphicsPenInfo>
{
public:
explicit wxGraphicsPenInfo(const wxColour& colour = wxColour(),
wxDouble width = 1.0,
wxPenStyle style = wxPENSTYLE_SOLID)
: wxPenInfoBase(colour, style)
{
m_width = width;
}
// Setters
wxGraphicsPenInfo& Width(wxDouble width)
{ m_width = width; return *this; }
// Accessors
wxDouble GetWidth() const { return m_width; }
private:
wxDouble m_width;
};
class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject
{
public:
@@ -479,7 +508,10 @@ public:
wxGraphicsPath CreatePath() const;
virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
wxGraphicsPen CreatePen(const wxPen& pen) const;
wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) const
{ return DoCreatePen(info); }
virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) const;
@@ -744,6 +776,8 @@ protected:
// implementations of overloaded public functions: we use different names
// for them to avoid the virtual function hiding problems in the derived
// classes
virtual wxGraphicsPen DoCreatePen(const wxGraphicsPenInfo& info) const;
virtual void DoDrawText(const wxString& str, wxDouble x, wxDouble y) = 0;
virtual void DoDrawRotatedText(const wxString& str, wxDouble x, wxDouble y,
wxDouble angle);
@@ -861,7 +895,7 @@ public:
// Paints
virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0;
virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) = 0;
virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) = 0;

View File

@@ -20,6 +20,8 @@ public:
wxPen( const wxColour &colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID );
wxPen( const wxPenInfo& info );
virtual ~wxPen();
bool operator==(const wxPen& pen) const;

View File

@@ -38,6 +38,8 @@ public:
wxPen( const wxColour &colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID );
wxPen( const wxPenInfo& info );
bool operator==(const wxPen& pen) const;
bool operator!=(const wxPen& pen) const { return !(*this == pen); }

View File

@@ -25,6 +25,9 @@ public:
wxPen(const wxColour& col, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);
wxPen(const wxBitmap& stipple, int width);
wxPen(const wxPenInfo& info);
virtual ~wxPen() { }
bool operator==(const wxPen& pen) const;

View File

@@ -23,6 +23,9 @@ public:
wxPen(const wxColour& col, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);
wxPen(const wxBitmap& stipple, int width);
wxPen(const wxPenInfo& info);
virtual ~wxPen();
bool operator==(const wxPen& pen) const;

View File

@@ -12,51 +12,34 @@
#define _WX_PEN_H_BASE_
#include "wx/gdiobj.h"
#include "wx/gdicmn.h"
#include "wx/peninfobase.h"
enum wxPenStyle
// ----------------------------------------------------------------------------
// wxPenInfo contains all parameters describing a wxPen
// ----------------------------------------------------------------------------
class wxPenInfo : public wxPenInfoBase<wxPenInfo>
{
wxPENSTYLE_INVALID = -1,
public:
explicit wxPenInfo(const wxColour& colour = wxColour(),
int width = 1,
wxPenStyle style = wxPENSTYLE_SOLID)
: wxPenInfoBase(colour, style)
{
m_width = width;
}
wxPENSTYLE_SOLID = wxSOLID,
wxPENSTYLE_DOT = wxDOT,
wxPENSTYLE_LONG_DASH = wxLONG_DASH,
wxPENSTYLE_SHORT_DASH = wxSHORT_DASH,
wxPENSTYLE_DOT_DASH = wxDOT_DASH,
wxPENSTYLE_USER_DASH = wxUSER_DASH,
// Setters
wxPENSTYLE_TRANSPARENT = wxTRANSPARENT,
wxPenInfo& Width(int width)
{ m_width = width; return *this; }
wxPENSTYLE_STIPPLE_MASK_OPAQUE = wxSTIPPLE_MASK_OPAQUE,
wxPENSTYLE_STIPPLE_MASK = wxSTIPPLE_MASK,
wxPENSTYLE_STIPPLE = wxSTIPPLE,
// Accessors
wxPENSTYLE_BDIAGONAL_HATCH = wxHATCHSTYLE_BDIAGONAL,
wxPENSTYLE_CROSSDIAG_HATCH = wxHATCHSTYLE_CROSSDIAG,
wxPENSTYLE_FDIAGONAL_HATCH = wxHATCHSTYLE_FDIAGONAL,
wxPENSTYLE_CROSS_HATCH = wxHATCHSTYLE_CROSS,
wxPENSTYLE_HORIZONTAL_HATCH = wxHATCHSTYLE_HORIZONTAL,
wxPENSTYLE_VERTICAL_HATCH = wxHATCHSTYLE_VERTICAL,
wxPENSTYLE_FIRST_HATCH = wxHATCHSTYLE_FIRST,
wxPENSTYLE_LAST_HATCH = wxHATCHSTYLE_LAST
};
int GetWidth() const { return m_width; }
enum wxPenJoin
{
wxJOIN_INVALID = -1,
wxJOIN_BEVEL = 120,
wxJOIN_MITER,
wxJOIN_ROUND
};
enum wxPenCap
{
wxCAP_INVALID = -1,
wxCAP_ROUND = 130,
wxCAP_PROJECTING,
wxCAP_BUTT
private:
int m_width;
};

130
include/wx/peninfobase.h Normal file
View File

@@ -0,0 +1,130 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/peninfobase.h
// Purpose: Declaration of wxPenInfoBase class and related constants
// Author: Adrien Tétar, Vadim Zeitlin
// Created: 2017-09-10
// Copyright: (c) 2017 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PENINFOBASE_H_
#define _WX_PENINFOBASE_H_
#include "wx/bitmap.h"
#include "wx/colour.h"
#include "wx/gdicmn.h" // for wxDash
enum wxPenStyle
{
wxPENSTYLE_INVALID = -1,
wxPENSTYLE_SOLID = wxSOLID,
wxPENSTYLE_DOT = wxDOT,
wxPENSTYLE_LONG_DASH = wxLONG_DASH,
wxPENSTYLE_SHORT_DASH = wxSHORT_DASH,
wxPENSTYLE_DOT_DASH = wxDOT_DASH,
wxPENSTYLE_USER_DASH = wxUSER_DASH,
wxPENSTYLE_TRANSPARENT = wxTRANSPARENT,
wxPENSTYLE_STIPPLE_MASK_OPAQUE = wxSTIPPLE_MASK_OPAQUE,
wxPENSTYLE_STIPPLE_MASK = wxSTIPPLE_MASK,
wxPENSTYLE_STIPPLE = wxSTIPPLE,
wxPENSTYLE_BDIAGONAL_HATCH = wxHATCHSTYLE_BDIAGONAL,
wxPENSTYLE_CROSSDIAG_HATCH = wxHATCHSTYLE_CROSSDIAG,
wxPENSTYLE_FDIAGONAL_HATCH = wxHATCHSTYLE_FDIAGONAL,
wxPENSTYLE_CROSS_HATCH = wxHATCHSTYLE_CROSS,
wxPENSTYLE_HORIZONTAL_HATCH = wxHATCHSTYLE_HORIZONTAL,
wxPENSTYLE_VERTICAL_HATCH = wxHATCHSTYLE_VERTICAL,
wxPENSTYLE_FIRST_HATCH = wxHATCHSTYLE_FIRST,
wxPENSTYLE_LAST_HATCH = wxHATCHSTYLE_LAST
};
enum wxPenJoin
{
wxJOIN_INVALID = -1,
wxJOIN_BEVEL = 120,
wxJOIN_MITER,
wxJOIN_ROUND
};
enum wxPenCap
{
wxCAP_INVALID = -1,
wxCAP_ROUND = 130,
wxCAP_PROJECTING,
wxCAP_BUTT
};
// ----------------------------------------------------------------------------
// wxPenInfoBase is a common base for wxPenInfo and wxGraphicsPenInfo
// ----------------------------------------------------------------------------
// This class uses CRTP, the template parameter is the derived class itself.
template <class T>
class wxPenInfoBase
{
public:
// Setters for the various attributes. All of them return the object itself
// so that the calls to them could be chained.
T& Colour(const wxColour& colour)
{ m_colour = colour; return This(); }
T& Style(wxPenStyle style)
{ m_style = style; return This(); }
T& Stipple(const wxBitmap& stipple)
{ m_stipple = stipple; m_style = wxPENSTYLE_STIPPLE; return This(); }
T& Dashes(int nb_dashes, const wxDash *dash)
{ m_nb_dashes = nb_dashes; m_dash = (wxDash *)dash; return This(); }
T& Join(wxPenJoin join)
{ m_join = join; return This(); }
T& Cap(wxPenCap cap)
{ m_cap = cap; return This(); }
// Accessors are mostly meant to be used by wxWidgets itself.
wxColour GetColour() const { return m_colour; }
wxBitmap GetStipple() const { return m_stipple; }
wxPenStyle GetStyle() const { return m_style; }
wxPenJoin GetJoin() const { return m_join; }
wxPenCap GetCap() const { return m_cap; }
int GetDashes(wxDash **ptr) const { *ptr = m_dash; return m_nb_dashes; }
int GetDashCount() const { return m_nb_dashes; }
wxDash* GetDash() const { return m_dash; }
// Convenience
bool IsTransparent() const { return m_style == wxPENSTYLE_TRANSPARENT; }
protected:
wxPenInfoBase(const wxColour& colour, wxPenStyle style)
{
m_nb_dashes = 0;
m_dash = NULL;
m_join = wxJOIN_ROUND;
m_cap = wxCAP_ROUND;
m_colour = colour;
m_style = style;
}
private:
// Helper to return this object itself cast to its real type T.
T& This() { return static_cast<T&>(*this); }
wxColour m_colour;
wxBitmap m_stipple;
wxPenStyle m_style;
wxPenJoin m_join;
wxPenCap m_cap;
int m_nb_dashes;
wxDash* m_dash;
};
#endif // _WX_PENINFOBASE_H_

View File

@@ -36,6 +36,9 @@ public:
wxPen( const wxColour &colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID );
wxPen( const wxBitmap &stipple, int width );
wxPen( const wxPenInfo& info );
virtual ~wxPen();
bool operator == ( const wxPen& pen ) const;