KiCad PCB EDA Suite
KIGFX::PREVIEW Namespace Reference

Classes

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

75 {
76  wxString str;
77 
78  if( prefix.size() )
79  str << prefix << ": ";
80 
81  str << formatPreviewDimension( aVal, aUnits );
82  return str;
83 }
static wxString formatPreviewDimension(double aVal, EDA_UNITS_T aUnits)
const string & str
Definition: json11.cpp:596

References formatPreviewDimension(), and str.

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

99 {
100  auto gal = aView->GetGAL();
101  auto glyphSize = gal->GetGlyphSize();
102  auto rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( aView->GetPainter()->GetSettings() );
103 
104  const auto lineSpace = glyphSize.y * 0.2;
105  auto linePitch = glyphSize.y + lineSpace;
106 
107  // radius string goes on the right of the cursor centre line
108  // with a small horizontal offset (enough to keep clear of a
109  // system cursor if present)
110  auto textPos = aCursorPos;
111 
112  // if the text goes above the cursor, shift it up
113  if( aTextQuadrant.y > 0 )
114  {
115  textPos.y -= linePitch * ( aStrings.size() + 1 );
116  }
117 
118  if( aTextQuadrant.x < 0 )
119  {
120  gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT );
121  textPos.x += 15.0 / gal->GetWorldScale();
122  }
123  else
124  {
125  gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT );
126  textPos.x -= 15.0 / gal->GetWorldScale();
127  }
128 
129  gal->SetStrokeColor( rs->GetLayerColor( LAYER_AUX_ITEMS ).WithAlpha(
130  PreviewOverlayDeemphAlpha( true ) ) );
131  gal->SetIsFill( false );
132 
133  // write strings top-to-bottom
134  for( const auto& str : aStrings )
135  {
136  textPos.y += linePitch;
137  gal->BitmapText( str, textPos, 0.0 );
138  }
139 }
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
const string & str
Definition: json11.cpp:596
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 GetSettings 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(), str, 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 86 of file preview_utils.cpp.

87 {
88  aHeight /= aGal.GetWorldScale();
89 
90  auto glyphSize = aGal.GetGlyphSize();
91  glyphSize = glyphSize * ( aHeight / glyphSize.y );
92  aGal.SetGlyphSize( glyphSize );
93 }
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().