KiCad PCB EDA Suite
KIGFX::WS_PAINTER Class Reference

WS_PAINTER Contains methods for drawing worksheet items. More...

#include <ws_painter.h>

Inheritance diagram for KIGFX::WS_PAINTER:
KIGFX::PAINTER

Public Member Functions

 WS_PAINTER (GAL *aGal)
 
virtual bool Draw (const VIEW_ITEM *, int) override
 Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the item. More...
 
void DrawBorder (const PAGE_INFO *aPageInfo, int aScaleFactor) const
 
virtual void ApplySettings (const RENDER_SETTINGS *aSettings) override
 Function ApplySettings Loads colors and display modes settings that are going to be used when drawing items. More...
 
virtual RENDER_SETTINGSGetSettings () override
 
void SetGAL (GAL *aGal)
 Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one. More...
 

Protected Attributes

GALm_gal
 Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg. More...
 
COLOR4D m_brightenedColor
 Color of brightened item frame. More...
 

Private Member Functions

void draw (const WS_DRAW_ITEM_LINE *aItem, int aLayer) const
 
void draw (const WS_DRAW_ITEM_RECT *aItem, int aLayer) const
 
void draw (const WS_DRAW_ITEM_POLYPOLYGONS *aItem, int aLayer) const
 
void draw (const WS_DRAW_ITEM_TEXT *aItem, int aLayer) const
 
void draw (const WS_DRAW_ITEM_BITMAP *aItem, int aLayer) const
 
void draw (const WS_DRAW_ITEM_PAGE *aItem, int aLayer) const
 

Private Attributes

WS_RENDER_SETTINGS m_renderSettings
 

Detailed Description

WS_PAINTER Contains methods for drawing worksheet items.

Definition at line 100 of file ws_painter.h.

Constructor & Destructor Documentation

◆ WS_PAINTER()

KIGFX::WS_PAINTER::WS_PAINTER ( GAL aGal)
inline

Definition at line 103 of file ws_painter.h.

103  :
104  PAINTER( aGal )
105  { }
PAINTER(GAL *aGal)
Constructor PAINTER( GAL* ) initializes this object for painting on any of the polymorphic GRAPHICS_A...
Definition: painter.cpp:32

Member Function Documentation

◆ ApplySettings()

virtual void KIGFX::WS_PAINTER::ApplySettings ( const RENDER_SETTINGS aSettings)
inlineoverridevirtual

Function ApplySettings Loads colors and display modes settings that are going to be used when drawing items.

Parameters
aSettingsare settings to be applied.

Implements KIGFX::PAINTER.

Definition at line 113 of file ws_painter.h.

114  {
115  m_renderSettings = *static_cast<const WS_RENDER_SETTINGS*>( aSettings );
116  }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130

References m_renderSettings.

◆ Draw()

bool KIGFX::WS_PAINTER::Draw ( const VIEW_ITEM aItem,
int  aLayer 
)
overridevirtual

Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the item.

Parameters
aItemis an item to be drawn.
aLayertells which layer is currently rendered so that draw functions may know what to draw (eg. for pads there are separate layers for holes, because they have other dimensions then the pad itself.

Implements KIGFX::PAINTER.

Definition at line 263 of file ws_painter.cpp.

264 {
265  auto item = static_cast<const EDA_ITEM*>( aItem );
266 
267  switch( item->Type() )
268  {
269  case WSG_LINE_T: draw( (WS_DRAW_ITEM_LINE*) item, aLayer ); break;
270  case WSG_POLY_T: draw( (WS_DRAW_ITEM_POLYPOLYGONS*) item, aLayer ); break;
271  case WSG_RECT_T: draw( (WS_DRAW_ITEM_RECT*) item, aLayer ); break;
272  case WSG_TEXT_T: draw( (WS_DRAW_ITEM_TEXT*) item, aLayer ); break;
273  case WSG_BITMAP_T: draw( (WS_DRAW_ITEM_BITMAP*) item, aLayer ); break;
274  case WSG_PAGE_T: draw( (WS_DRAW_ITEM_PAGE*) item, aLayer ); break;
275  default: return false;
276  }
277 
278  return true;
279 }
void draw(const WS_DRAW_ITEM_LINE *aItem, int aLayer) const
Definition: ws_painter.cpp:282

References WSG_BITMAP_T, WSG_LINE_T, WSG_PAGE_T, WSG_POLY_T, WSG_RECT_T, and WSG_TEXT_T.

Referenced by KIGFX::WS_PROXY_VIEW_ITEM::ViewDraw().

◆ draw() [1/6]

void KIGFX::WS_PAINTER::draw ( const WS_DRAW_ITEM_LINE aItem,
int  aLayer 
) const
private

Definition at line 282 of file ws_painter.cpp.

283 {
284  m_gal->SetIsStroke( true );
285  m_gal->SetIsFill( false );
286  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
288  m_gal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
289 }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:130
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
virtual void SetLineWidth(float aLineWidth)
Set the line width.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
const wxPoint & GetStart() const
Definition: ws_draw_item.h:128
virtual int GetPenWidth() const
Definition: ws_draw_item.h:75
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
Definition: ws_painter.cpp:70
int GetDefaultPenWidth() const
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References WS_DRAW_ITEM_LINE::GetEnd(), WS_DRAW_ITEM_BASE::GetPenWidth(), and WS_DRAW_ITEM_LINE::GetStart().

◆ draw() [2/6]

void KIGFX::WS_PAINTER::draw ( const WS_DRAW_ITEM_RECT aItem,
int  aLayer 
) const
private

Definition at line 292 of file ws_painter.cpp.

293 {
294  m_gal->SetIsStroke( true );
295  m_gal->SetIsFill( false );
296  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
298  m_gal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
299 }
const wxPoint & GetStart() const
Definition: ws_draw_item.h:208
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:210
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
virtual void SetLineWidth(float aLineWidth)
Set the line width.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual int GetPenWidth() const
Definition: ws_draw_item.h:75
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
Definition: ws_painter.cpp:70
int GetDefaultPenWidth() const
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References WS_DRAW_ITEM_RECT::GetEnd(), WS_DRAW_ITEM_BASE::GetPenWidth(), and WS_DRAW_ITEM_RECT::GetStart().

◆ draw() [3/6]

void KIGFX::WS_PAINTER::draw ( const WS_DRAW_ITEM_POLYPOLYGONS aItem,
int  aLayer 
) const
private

Definition at line 302 of file ws_painter.cpp.

303 {
304  m_gal->SetFillColor( m_renderSettings.GetColor( aItem, aLayer ) );
305  m_gal->SetIsFill( true );
306  m_gal->SetIsStroke( false );
307 
309 
310  for( int idx = 0; idx < item->GetPolygons().OutlineCount(); ++idx )
311  {
312  SHAPE_LINE_CHAIN& outline = item->GetPolygons().Outline( idx );
313  m_gal->DrawPolygon( outline );
314  }
315 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
int OutlineCount() const
Returns the number of outlines in the set
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130
SHAPE_POLY_SET & GetPolygons()
Definition: ws_draw_item.h:172
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
SHAPE_LINE_CHAIN.
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
Definition: ws_painter.cpp:70
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References WS_DRAW_ITEM_POLYPOLYGONS::GetPolygons(), SHAPE_POLY_SET::Outline(), and SHAPE_POLY_SET::OutlineCount().

◆ draw() [4/6]

void KIGFX::WS_PAINTER::draw ( const WS_DRAW_ITEM_TEXT aItem,
int  aLayer 
) const
private

Definition at line 318 of file ws_painter.cpp.

319 {
320  VECTOR2D position( aItem->GetTextPos().x, aItem->GetTextPos().y );
321  int penWidth = std::max( aItem->GetEffectiveTextPenWidth(),
323 
324  m_gal->Save();
325  m_gal->Translate( position );
326  m_gal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
327  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
328  m_gal->SetLineWidth( penWidth );
329  m_gal->SetTextAttributes( aItem );
330  m_gal->SetIsFill( false );
331  m_gal->SetIsStroke( true );
332  m_gal->StrokeText( aItem->GetShownText(), VECTOR2D( 0, 0 ), 0.0 );
333  m_gal->Restore();
334 }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130
virtual void SetTextAttributes(const EDA_TEXT *aText)
Loads attributes of the given text (bold/italic/underline/mirrored and so on).
double GetTextAngle() const
Definition: eda_text.h:173
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:152
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void Rotate(double aAngle)
Rotate the context.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void StrokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draws a vector type text using preloaded Newstroke font.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void Restore()
Restore the context.
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
Definition: ws_painter.cpp:70
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
virtual void Save()
Save the context.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:133

References EDA_TEXT::GetEffectiveTextPenWidth(), EDA_TEXT::GetShownText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), VECTOR2< T >::Rotate(), wxPoint::x, and wxPoint::y.

◆ draw() [5/6]

void KIGFX::WS_PAINTER::draw ( const WS_DRAW_ITEM_BITMAP aItem,
int  aLayer 
) const
private

Definition at line 337 of file ws_painter.cpp.

338 {
339  m_gal->Save();
340  auto* bitmap = static_cast<WS_DATA_ITEM_BITMAP*>( aItem->GetPeer() );
341 
342  VECTOR2D position = aItem->GetPosition();
343  m_gal->Translate( position );
344 
345  // When the image scale factor is not 1.0, we need to modify the actual scale
346  // as the image scale factor is similar to a local zoom
347  double img_scale = bitmap->m_ImageBitmap->GetScale();
348 
349  if( img_scale != 1.0 )
350  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
351 
352  m_gal->DrawBitmap( *bitmap->m_ImageBitmap );
353 
354 #if 0 // For bounding box debug purpose only
355  EDA_RECT bbox = aItem->GetBoundingBox();
356  m_gal->SetIsFill( true );
357  m_gal->SetIsStroke( true );
358  m_gal->SetFillColor( COLOR4D( 1, 1, 1, 0.4 ) );
359  m_gal->SetStrokeColor( COLOR4D( 0, 0, 0, 1 ) );
360 
361  if( img_scale != 1.0 )
362  m_gal->Scale( VECTOR2D( 1.0, 1.0 ) );
363 
364  m_gal->DrawRectangle( VECTOR2D( bbox.GetOrigin() ) - position,
365  VECTOR2D( bbox.GetEnd() ) - position );
366 #endif
367 
368  m_gal->Restore();
369 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
WS_DATA_ITEM * GetPeer() const
Definition: ws_draw_item.h:67
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
virtual void DrawBitmap(const BITMAP_BASE &aBitmap)
Draw a bitmap image.
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
const wxPoint GetEnd() const
Definition: eda_rect.h:116
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void Restore()
Restore the context.
const wxPoint GetPosition() const override
Definition: ws_draw_item.h:328
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
virtual void Save()
Save the context.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40

References WS_DRAW_ITEM_BITMAP::GetBoundingBox(), EDA_RECT::GetEnd(), EDA_RECT::GetOrigin(), WS_DRAW_ITEM_BASE::GetPeer(), and WS_DRAW_ITEM_BITMAP::GetPosition().

◆ draw() [6/6]

void KIGFX::WS_PAINTER::draw ( const WS_DRAW_ITEM_PAGE aItem,
int  aLayer 
) const
private

Definition at line 372 of file ws_painter.cpp.

373 {
374  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
375  VECTOR2D end = VECTOR2D( aItem->GetPageSize().x,
376  aItem->GetPageSize().y );
377 
378  m_gal->SetIsStroke( true );
379 
380  // Use a gray color for the border color
382  m_gal->SetIsFill( false );
383  m_gal->DrawRectangle( origin, end );
384 
385  // Draw the corner marker
386  double marker_size = aItem->GetMarkerSize();
387 
389  VECTOR2D pos = VECTOR2D( aItem->GetMarkerPos().x, aItem->GetMarkerPos().y );
390 
391  // Draw a cirle and a X
392  m_gal->DrawCircle( pos, marker_size );
393  m_gal->DrawLine( VECTOR2D( pos.x - marker_size, pos.y - marker_size),
394  VECTOR2D( pos.x + marker_size, pos.y + marker_size ) );
395  m_gal->DrawLine( VECTOR2D( pos.x + marker_size, pos.y - marker_size),
396  VECTOR2D( pos.x - marker_size, pos.y + marker_size ) );
397 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
wxSize GetPageSize() const
Definition: ws_draw_item.h:250
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
double GetMarkerSize() const
Definition: ws_draw_item.h:253
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
const wxPoint & GetMarkerPos() const
Definition: ws_draw_item.h:251

References WS_DRAW_ITEM_PAGE::GetMarkerPos(), WS_DRAW_ITEM_PAGE::GetMarkerSize(), WS_DRAW_ITEM_PAGE::GetPageSize(), wxPoint::x, VECTOR2< T >::x, wxPoint::y, and VECTOR2< T >::y.

◆ DrawBorder()

void KIGFX::WS_PAINTER::DrawBorder ( const PAGE_INFO aPageInfo,
int  aScaleFactor 
) const

Definition at line 400 of file ws_painter.cpp.

401 {
402  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
403  VECTOR2D end = VECTOR2D( aPageInfo->GetWidthMils() * aScaleFactor,
404  aPageInfo->GetHeightMils() * aScaleFactor );
405 
406  m_gal->SetIsStroke( true );
407  // Use a gray color for the border color
409  m_gal->SetIsFill( false );
410  m_gal->DrawRectangle( origin, end );
411 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130
int GetHeightMils() const
Definition: page_info.h:140
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
int GetWidthMils() const
Definition: page_info.h:137

References PAGE_INFO::GetHeightMils(), and PAGE_INFO::GetWidthMils().

Referenced by KIGFX::WS_PROXY_VIEW_ITEM::ViewDraw().

◆ GetSettings()

virtual RENDER_SETTINGS* KIGFX::WS_PAINTER::GetSettings ( )
inlineoverridevirtual

Implements KIGFX::PAINTER.

Definition at line 119 of file ws_painter.h.

119 { return &m_renderSettings; }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130

References m_renderSettings.

Referenced by KIGFX::WS_PROXY_VIEW_ITEM::ViewDraw().

◆ SetGAL()

void KIGFX::PAINTER::SetGAL ( GAL aGal)
inlineinherited

Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one.

Parameters
aGalis the new GAL instance.

Definition at line 78 of file painter.h.

79  {
80  m_gal = aGal;
81  }
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110

References KIGFX::PAINTER::m_gal.

Member Data Documentation

◆ m_brightenedColor

COLOR4D KIGFX::PAINTER::m_brightenedColor
protectedinherited

Color of brightened item frame.

Definition at line 113 of file painter.h.

◆ m_gal

◆ m_renderSettings

WS_RENDER_SETTINGS KIGFX::WS_PAINTER::m_renderSettings
private

Definition at line 130 of file ws_painter.h.

Referenced by ApplySettings(), and GetSettings().


The documentation for this class was generated from the following files: