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  GEOM_SHAPE {
  GEOM_SHAPE::SEGMENT = 0, GEOM_SHAPE::RECT, GEOM_SHAPE::ARC, GEOM_SHAPE::CIRCLE,
  GEOM_SHAPE::POLYGON, GEOM_SHAPE::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, 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 SetConstantGlyphHeight (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

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:32

Function Documentation

◆ DimensionLabel()

wxString KIGFX::PREVIEW::DimensionLabel ( const wxString &  prefix,
double  aVal,
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.

35 {
36  wxString str;
37 
38  if( prefix.size() )
39  str << prefix << ": ";
40 
41  wxString fmtStr;
42 
43  // show a sane precision for the preview, which doesn't need to be accurate down to the
44  // nanometre
45  switch( aUnits )
46  {
47  case EDA_UNITS::MILLIMETRES: fmtStr = wxT( "%.3f" ); break; // 1um
48  case EDA_UNITS::MILS: fmtStr = wxT( "%.1f" ); break; // 0.1mil
49  case EDA_UNITS::INCHES: fmtStr = wxT( "%.4f" ); break; // 0.1mil
50  case EDA_UNITS::DEGREES: fmtStr = wxT( "%.1f" ); break; // 0.1deg
51  case EDA_UNITS::PERCENT: fmtStr = wxT( "%.1f" ); break; // 0.1%
52  case EDA_UNITS::UNSCALED: fmtStr = wxT( "%f" ); break;
53  }
54 
55  str << wxString::Format( fmtStr, To_User_Unit( aUnits, aVal ) );
56 
57  if( aIncludeUnits )
58  str << " " << GetAbbreviatedUnitsLabel( aUnits );
59 
60  return str;
61 }
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:424
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
double To_User_Unit(EDA_UNITS aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:68

References DEGREES, Format(), GetAbbreviatedUnitsLabel(), INCHES, MILLIMETRES, MILS, PERCENT, To_User_Unit(), 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 117 of file preview_utils.cpp.

121 {
122  KIGFX::GAL* gal = aView->GetGAL();
123  RENDER_SETTINGS* rs = aView->GetPainter()->GetSettings();
124 
125  // constant text size on screen
126  TEXT_DIMS textDims = SetConstantGlyphHeight( gal );
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  {
137  textPos.y -= textDims.LinePitch * ( aStrings.size() + 1 );
138  }
139 
140  if( aTextQuadrant.x < 0 )
141  {
142  if( viewFlipped )
144  else
146 
147  textPos.x += 15.0 / gal->GetWorldScale();
148 
149  if( aDrawingDropShadows )
150  textPos.x -= textDims.ShadowWidth;
151  }
152  else
153  {
154  if( viewFlipped )
156  else
158 
159  textPos.x -= 15.0 / gal->GetWorldScale();
160 
161  if( aDrawingDropShadows )
162  textPos.x += textDims.ShadowWidth;
163  }
164 
165  gal->SetIsFill( false );
167  gal->SetLineWidth( textDims.StrokeWidth );
168  gal->SetTextMirrored( viewFlipped ); // Prevent text flipping when view is flipped
169 
170  if( aDrawingDropShadows )
171  {
172  gal->SetStrokeColor( GetShadowColor( gal->GetStrokeColor() ) );
173  gal->SetLineWidth( gal->GetLineWidth() + 2 * textDims.ShadowWidth );
174  }
175 
176  // write strings top-to-bottom
177  for( const wxString& str : aStrings )
178  {
179  textPos.y += textDims.LinePitch;
180  gal->StrokeText( str, textPos, 0.0 );
181  }
182 }
float GetLineWidth() const
Get the line width.
Auxiliary items (guides, rule, etc)
Definition: layer_ids.h:218
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
TEXT_DIMS SetConstantGlyphHeight(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.
bool IsFlippedX() const
Return true if flip flag for the X axis is set.
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:190
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:208
virtual void SetLineWidth(float aLineWidth)
Set the line width.
const COLOR4D & GetStrokeColor() const
Get the stroke color.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void StrokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a vector type text using preloaded Newstroke font.
void SetTextMirrored(bool aMirrored)
Set a mirrored property of text.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
double GetWorldScale() const
Get the world scale.
Abstract interface for drawing on a 2D-surface.
COLOR4D GetShadowColor(const COLOR4D &aColor)

References KIGFX::VIEW::GetGAL(), KIGFX::RENDER_SETTINGS::GetLayerColor(), KIGFX::GAL::GetLineWidth(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), GetShadowColor(), KIGFX::GAL::GetStrokeColor(), KIGFX::GAL::GetWorldScale(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, KIGFX::GAL::IsFlippedX(), LAYER_AUX_ITEMS, KIGFX::PREVIEW::TEXT_DIMS::LinePitch, SetConstantGlyphHeight(), KIGFX::GAL::SetHorizontalJustify(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), KIGFX::GAL::SetTextMirrored(), KIGFX::PREVIEW::TEXT_DIMS::ShadowWidth, KIGFX::GAL::StrokeText(), 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().

◆ GetShadowColor()

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

Definition at line 108 of file preview_utils.cpp.

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

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().

◆ SetConstantGlyphHeight()

KIGFX::PREVIEW::TEXT_DIMS KIGFX::PREVIEW::SetConstantGlyphHeight ( 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 64 of file preview_utils.cpp.

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

References KIGFX::GAL::GetGlyphSize(), HIDPI_GL_CANVAS::GetScaleFactor(), KIGFX::GAL::GetWorldScale(), KIGFX::PREVIEW::TEXT_DIMS::LinePitch, KIGFX::GAL::SetGlyphSize(), KIGFX::PREVIEW::TEXT_DIMS::ShadowWidth, KIGFX::PREVIEW::TEXT_DIMS::StrokeWidth, VECTOR2< T >::x, and VECTOR2< T >::y.

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