KiCad PCB EDA Suite
KIGFX::PREVIEW Namespace Reference

Classes

class  ARC_ASSISTANT
 SELECTION_AREA. More...
 
class  ARC_GEOM_MANAGER
 ARC_GEOM_MANAGER. More...
 
class  CENTRELINE_RECT_ITEM
 CENTRELINE_RECT_ITEM. 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
 POLYGON_ITEM. More...
 
class  RULER_ITEM
 RULER_ITEM. More...
 
class  SELECTION_AREA
 SELECTION_AREA. 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...
 
class  TWO_POINT_GEOMETRY_MANAGER
 TWO_POINT_GEOMETRY_MANAGER. More...
 

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)
 Get a formatted string showing a dimension to a sane precision with an optional prefix and unit suffix. More...
 
void SetConstantGlyphHeight (KIGFX::GAL &aGal, double aHeight)
 Set the GAL glyph height to a constant scaled value, so that it always looks the same on screen. More...
 
void DrawTextNextToCursor (KIGFX::VIEW *aView, const VECTOR2D &aCursorPos, const VECTOR2D &aTextQuadrant, const std::vector< wxString > &aStrings)
 Draw strings next to the cursor. More...
 

Function Documentation

◆ DimensionLabel()

wxString KIGFX::PREVIEW::DimensionLabel ( const wxString &  prefix,
double  aVal,
EDA_UNITS  aUnits 
)

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

Definition at line 73 of file preview_utils.cpp.

74 {
75  wxString str;
76 
77  if( prefix.size() )
78  str << prefix << ": ";
79 
80  str << formatPreviewDimension( aVal, aUnits );
81  return str;
82 }
static wxString formatPreviewDimension(double aVal, EDA_UNITS aUnits)

References formatPreviewDimension().

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

◆ DrawTextNextToCursor()

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

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 95 of file preview_utils.cpp.

98 {
99  auto gal = aView->GetGAL();
100  auto glyphSize = gal->GetGlyphSize();
101  auto rs = aView->GetPainter()->GetSettings();
102 
103  const auto lineSpace = glyphSize.y * 0.2;
104  auto linePitch = glyphSize.y + lineSpace;
105 
106  // radius string goes on the right of the cursor centre line
107  // with a small horizontal offset (enough to keep clear of a
108  // system cursor if present)
109  auto textPos = aCursorPos;
110 
111  // if the text goes above the cursor, shift it up
112  if( aTextQuadrant.y > 0 )
113  {
114  textPos.y -= linePitch * ( aStrings.size() + 1 );
115  }
116 
117  if( aTextQuadrant.x < 0 )
118  {
119  gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT );
120  textPos.x += 15.0 / gal->GetWorldScale();
121  }
122  else
123  {
124  gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT );
125  textPos.x -= 15.0 / gal->GetWorldScale();
126  }
127 
128  gal->SetStrokeColor( rs->GetLayerColor( LAYER_AUX_ITEMS ).WithAlpha(
129  PreviewOverlayDeemphAlpha( true ) ) );
130  gal->SetIsFill( false );
131 
132  // write strings top-to-bottom
133  for( const auto& str : aStrings )
134  {
135  textPos.y += linePitch;
136  gal->BitmapText( str, textPos, 0.0 );
137  }
138 }
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
const VECTOR2D & GetGlyphSize() const
Auxiliary items (guides, rule, etc)
double PreviewOverlayDeemphAlpha(bool aDeemph=true)
Default alpha of "de-emphasised" features (like previously locked-in lines.
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGlyphSize(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, LAYER_AUX_ITEMS, PreviewOverlayDeemphAlpha(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

◆ PreviewOverlayDeemphAlpha()

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

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

Definition at line 26 of file preview_utils.cpp.

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

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

◆ SetConstantGlyphHeight()

void KIGFX::PREVIEW::SetConstantGlyphHeight ( KIGFX::GAL aGal,
double  aHeight 
)

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
aHeightthe height of the glyph, in pixels

Definition at line 85 of file preview_utils.cpp.

86 {
87  aHeight /= aGal.GetWorldScale();
88 
89  auto glyphSize = aGal.GetGlyphSize();
90  glyphSize = glyphSize * ( aHeight / glyphSize.y );
91  aGal.SetGlyphSize( glyphSize );
92 }
const VECTOR2D & GetGlyphSize() const
void SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
double GetWorldScale() const
Get the world scale.

References KIGFX::GAL::GetGlyphSize(), KIGFX::GAL::GetWorldScale(), and KIGFX::GAL::SetGlyphSize().

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