KiCad PCB EDA Suite
KIGFX::PREVIEW Namespace Reference

Classes

class  ARC_ASSISTANT
 Represents an assistant draw when interactively drawing an arc on a canvas. More...
 
class  ARC_GEOM_MANAGER
 Manage the construction of a circular arc though sequential setting of critical points: center, arc start and arc end. More...
 
class  CENTRELINE_RECT_ITEM
 Represent an area drawn by drawing a rectangle of a given aspect along a vector, with the midpoint of one side on the start point and the mid point of the opposite side on the end. More...
 
class  DRAW_CONTEXT
 A KIGFX::PREVIEW::DRAW_CONTEXT is a wrapper around a GAL and some other settings that makes it easy to draw preview items consistently. More...
 
class  MULTISTEP_GEOM_MANAGER
 A geometry manager that works by accepting a sequence of points and advancing though stages of geometric construction with each point "locked in". More...
 
class  POLYGON_ITEM
 A preview item which shows an in-progress polygon, which can be used for zone outlines, etc. More...
 
class  RULER_ITEM
 A drawn ruler item for showing the distance between two points. More...
 
class  SELECTION_AREA
 Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between two points. More...
 
class  SIMPLE_OVERLAY_ITEM
 SIMPLE_OVERLAY_ITEM is class that represents a visual area drawn on a canvas, used to temporarily demarcate an area or show something on an overlay. More...
 
struct  TEXT_DIMS
 
class  TWO_POINT_ASSISTANT
 Represents an assistant draw when interactively drawing a line or circle on a canvas. More...
 
class  TWO_POINT_GEOMETRY_MANAGER
 Represent a very simple geometry manager for items that have a start and end point. More...
 

Enumerations

enum class  GEOM_SHAPE {
  SEGMENT = 0 , RECT , ARC , CIRCLE ,
  POLYGON , CURVE
}
 

Functions

double PreviewOverlayDeemphAlpha (bool aDeemph=true)
 Default alpha of "de-emphasised" features (like previously locked-in lines. More...
 
wxString DimensionLabel (const wxString &prefix, double aVal, const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, bool aIncludeUnits=true)
 Get a formatted string showing a dimension to a sane precision with an optional prefix and unit suffix. More...
 
TEXT_DIMS GetConstantGlyphHeight (KIGFX::GAL *aGal, int aRelativeSize=0)
 Set the GAL glyph height to a constant scaled value, so that it always looks the same on screen. More...
 
COLOR4D GetShadowColor (const COLOR4D &aColor)
 
void DrawTextNextToCursor (KIGFX::VIEW *aView, const VECTOR2D &aCursorPos, const VECTOR2D &aTextQuadrant, const std::vector< wxString > &aStrings, bool aDrawingDropShadows)
 Draw strings next to the cursor. More...
 

Enumeration Type Documentation

◆ GEOM_SHAPE

enum class KIGFX::PREVIEW::GEOM_SHAPE
strong
Enumerator
SEGMENT 
RECT 
ARC 
CIRCLE 
POLYGON 
CURVE 

Definition at line 37 of file two_point_assistant.h.

38{
39 SEGMENT = 0,
40 RECT,
41 ARC,
42 CIRCLE,
43 POLYGON,
44 CURVE
45};
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:33

Function Documentation

◆ DimensionLabel()

wxString KIGFX::PREVIEW::DimensionLabel ( const wxString &  prefix,
double  aVal,
const EDA_IU_SCALE aIuScale,
EDA_UNITS  aUnits,
bool  aIncludeUnits = true 
)

Get a formatted string showing a dimension to a sane precision with an optional prefix and unit suffix.

Definition at line 33 of file preview_utils.cpp.

36{
37 wxString str;
38
39 if( prefix.size() )
40 str << prefix << ": ";
41
42 wxString fmtStr;
43
44 // show a sane precision for the preview, which doesn't need to be accurate down to the
45 // nanometre
46 switch( aUnits )
47 {
48 case EDA_UNITS::MILLIMETRES: fmtStr = wxT( "%.3f" ); break; // 1um
49 case EDA_UNITS::MILS: fmtStr = wxT( "%.1f" ); break; // 0.1mil
50 case EDA_UNITS::INCHES: fmtStr = wxT( "%.4f" ); break; // 0.1mil
51 case EDA_UNITS::DEGREES: fmtStr = wxT( "%.1f" ); break; // 0.1deg
52 case EDA_UNITS::PERCENT: fmtStr = wxT( "%.1f" ); break; // 0.1%
53 case EDA_UNITS::UNSCALED: fmtStr = wxT( "%f" ); break;
54 }
55
56 str << wxString::Format( fmtStr, EDA_UNIT_UTILS::UI::ToUserUnit( aIuScale, aUnits, aVal ) );
57
58 if( aIncludeUnits )
59 str << EDA_UNIT_UTILS::GetText( aUnits );
60
61 return str;
62}
double ToUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: eda_units.cpp:190
wxString GetText(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
Definition: eda_units.cpp:101
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References DEGREES, Format(), EDA_UNIT_UTILS::GetText(), INCHES, MILLIMETRES, MILS, PERCENT, EDA_UNIT_UTILS::UI::ToUserUnit(), and UNSCALED.

Referenced by drawCursorStrings(), drawTicksAlongLine(), KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw(), and KIGFX::PREVIEW::TWO_POINT_ASSISTANT::ViewDraw().

◆ DrawTextNextToCursor()

void KIGFX::PREVIEW::DrawTextNextToCursor ( KIGFX::VIEW aView,
const VECTOR2D aCursorPos,
const VECTOR2D aTextQuadrant,
const std::vector< wxString > &  aStrings,
bool  aDrawingDropShadows 
)

Draw strings next to the cursor.

Parameters
aGalthe GAL to draw on.
aCursorPosthe position of the cursor to draw next to.
aTextQuadranta vector pointing to the quadrant to draw the text in.
aStringslist of strings to draw, top to bottom.

Definition at line 116 of file preview_utils.cpp.

120{
121 KIGFX::GAL* gal = aView->GetGAL();
123
124 // constant text size on screen
125 TEXT_DIMS textDims = GetConstantGlyphHeight( gal );
126 TEXT_ATTRIBUTES textAttrs;
127
128 // radius string goes on the right of the cursor centre line with a small horizontal
129 // offset (enough to keep clear of a system cursor if present)
130 VECTOR2D textPos = aCursorPos;
131
132 bool viewFlipped = gal->IsFlippedX();
133
134 // if the text goes above the cursor, shift it up
135 if( aTextQuadrant.y > 0 )
136 textPos.y -= textDims.LinePitch * ( aStrings.size() + 1 );
137
138 if( aTextQuadrant.x < 0 )
139 {
140 if( viewFlipped )
142 else
143 textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
144
145 textPos.x += 15.0 / gal->GetWorldScale();
146 }
147 else
148 {
149 if( viewFlipped )
150 textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
151 else
153
154 textPos.x -= 15.0 / gal->GetWorldScale();
155 }
156
158 textAttrs.m_Mirrored = viewFlipped; // Prevent text flipping when view is flipped
159 textAttrs.m_Size = textDims.GlyphSize;
160 textAttrs.m_StrokeWidth = textDims.StrokeWidth;
161 gal->SetIsFill( false );
162 gal->SetIsStroke( true );
163
164 if( aDrawingDropShadows )
165 {
166 textAttrs.m_StrokeWidth = textDims.StrokeWidth + ( 2 * textDims.ShadowWidth );
168 }
169
170 // write strings top-to-bottom
171 for( const wxString& str : aStrings )
172 {
173 textPos.y += textDims.LinePitch;
174 font->Draw( gal, str, textPos, textAttrs );
175 }
176}
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:105
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:138
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttrs) const
Draw a string.
Definition: font.cpp:232
Abstract interface for drawing on a 2D-surface.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
const COLOR4D & GetStrokeColor() const
Get the stroke color.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
double GetWorldScale() const
Get the world scale.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:195
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:213
GR_TEXT_H_ALIGN_T m_Halign
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc)
Definition: layer_ids.h:222
COLOR4D GetShadowColor(const COLOR4D &aColor)
TEXT_DIMS GetConstantGlyphHeight(KIGFX::GAL *aGal, int aRelativeSize=0)
Set the GAL glyph height to a constant scaled value, so that it always looks the same on screen.
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT

References KIFONT::FONT::Draw(), GetConstantGlyphHeight(), KIFONT::FONT::GetFont(), KIGFX::VIEW::GetGAL(), KIGFX::RENDER_SETTINGS::GetLayerColor(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), GetShadowColor(), KIGFX::GAL::GetStrokeColor(), KIGFX::GAL::GetWorldScale(), KIGFX::PREVIEW::TEXT_DIMS::GlyphSize, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_H_ALIGN_RIGHT, KIGFX::GAL::IsFlippedX(), LAYER_AUX_ITEMS, KIGFX::PREVIEW::TEXT_DIMS::LinePitch, TEXT_ATTRIBUTES::m_Halign, TEXT_ATTRIBUTES::m_Mirrored, TEXT_ATTRIBUTES::m_Size, TEXT_ATTRIBUTES::m_StrokeWidth, KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetStrokeColor(), KIGFX::PREVIEW::TEXT_DIMS::ShadowWidth, KIGFX::PREVIEW::TEXT_DIMS::StrokeWidth, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by drawCursorStrings(), KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw(), and KIGFX::PREVIEW::TWO_POINT_ASSISTANT::ViewDraw().

◆ GetConstantGlyphHeight()

KIGFX::PREVIEW::TEXT_DIMS KIGFX::PREVIEW::GetConstantGlyphHeight ( KIGFX::GAL aGal,
int  aRelativeSize = 0 
)

Set the GAL glyph height to a constant scaled value, so that it always looks the same on screen.

Parameters
aGalthe GAL to draw on.
aRelativeSizesimilar to HTML font sizes; 0 will give a standard size while +1 etc. will give larger and -1 etc. will give smaller.
Returns
the text widths for the resulting glyph size.

Definition at line 65 of file preview_utils.cpp.

67{
68 constexpr double aspectRatio = 1.0;
69 constexpr double hdpiSizes[] = { 8, 9, 11, 13, 15 };
70 constexpr double sizes[] = { 10, 12, 14, 16, 18 };
71
72 double height;
73 double thicknessFactor;
74 double shadowFactor;
75 double linePitchFactor;
76
77 HIDPI_GL_CANVAS* canvas = dynamic_cast<HIDPI_GL_CANVAS*>( aGal );
78
79 if( canvas && canvas->GetScaleFactor() > 1 )
80 {
81 height = hdpiSizes[ 2 + aRelativeSize ];
82 thicknessFactor = 0.15;
83 shadowFactor = 0.10;
84 linePitchFactor = 1.7;
85 }
86 else
87 {
88 height = sizes[ 2 + aRelativeSize ];
89 thicknessFactor = 0.20;
90 shadowFactor = 0.15;
91 linePitchFactor = 1.9;
92 }
93
94 height /= aGal->GetWorldScale();
95
96 TEXT_DIMS textDims;
97
98 textDims.GlyphSize = VECTOR2I( height * aspectRatio, height );
99 textDims.StrokeWidth = height * thicknessFactor;
100 textDims.ShadowWidth = height * shadowFactor;
101 textDims.LinePitch = height * linePitchFactor;
102
103 return textDims;
104}
wxGLCanvas wrapper for HiDPI/Retina support.
double GetScaleFactor() const
Get the current scale factor.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590

References HIDPI_GL_CANVAS::GetScaleFactor(), KIGFX::GAL::GetWorldScale(), KIGFX::PREVIEW::TEXT_DIMS::GlyphSize, KIGFX::PREVIEW::TEXT_DIMS::LinePitch, KIGFX::PREVIEW::TEXT_DIMS::ShadowWidth, and KIGFX::PREVIEW::TEXT_DIMS::StrokeWidth.

Referenced by drawBacksideTicks(), DrawTextNextToCursor(), drawTicksAlongLine(), and KIGFX::PREVIEW::RULER_ITEM::ViewDraw().

◆ GetShadowColor()

KIGFX::COLOR4D KIGFX::PREVIEW::GetShadowColor ( const COLOR4D aColor)

Definition at line 107 of file preview_utils.cpp.

108{
109 if( aColor.GetBrightness() > 0.5 )
110 return COLOR4D::BLACK;
111 else
112 return COLOR4D::WHITE;
113}
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
Definition: color4d.h:331
@ WHITE
Definition: color4d.h:46
@ BLACK
Definition: color4d.h:42

References BLACK, KIGFX::COLOR4D::GetBrightness(), and WHITE.

Referenced by DrawTextNextToCursor(), and KIGFX::PREVIEW::RULER_ITEM::ViewDraw().

◆ PreviewOverlayDeemphAlpha()

double KIGFX::PREVIEW::PreviewOverlayDeemphAlpha ( bool  aDeemph = true)

Default alpha of "de-emphasised" features (like previously locked-in lines.

Definition at line 27 of file preview_utils.cpp.

28{
29 return aDeemph ? 0.5 : 1.0;
30}

Referenced by deemphasise().