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 218 of file ws_painter.cpp.

219 {
220  auto item = static_cast<const EDA_ITEM*>( aItem );
221 
222  switch( item->Type() )
223  {
224  case WSG_LINE_T: draw( (WS_DRAW_ITEM_LINE*) item, aLayer ); break;
225  case WSG_POLY_T: draw( (WS_DRAW_ITEM_POLYPOLYGONS*) item, aLayer ); break;
226  case WSG_RECT_T: draw( (WS_DRAW_ITEM_RECT*) item, aLayer ); break;
227  case WSG_TEXT_T: draw( (WS_DRAW_ITEM_TEXT*) item, aLayer ); break;
228  case WSG_BITMAP_T: draw( (WS_DRAW_ITEM_BITMAP*) item, aLayer ); break;
229  case WSG_PAGE_T: draw( (WS_DRAW_ITEM_PAGE*) item, aLayer ); break;
230  default: return false;
231  }
232 
233  return true;
234 }
void draw(const WS_DRAW_ITEM_LINE *aItem, int aLayer) const
Definition: ws_painter.cpp:237

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 237 of file ws_painter.cpp.

238 {
239  m_gal->SetIsStroke( true );
240  m_gal->SetIsFill( false );
241  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
243  m_gal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
244 }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:133
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:131
virtual int GetPenWidth() const
Definition: ws_draw_item.h:78
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:71
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 247 of file ws_painter.cpp.

248 {
249  m_gal->SetIsStroke( true );
250  m_gal->SetIsFill( false );
251  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
253  m_gal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
254 }
const wxPoint & GetStart() const
Definition: ws_draw_item.h:211
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:213
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:78
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:71
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 257 of file ws_painter.cpp.

258 {
259  m_gal->SetFillColor( m_renderSettings.GetColor( aItem, aLayer ) );
260  m_gal->SetIsFill( true );
261  m_gal->SetIsStroke( false );
262 
264 
265  for( int idx = 0; idx < item->GetPolygons().OutlineCount(); ++idx )
266  {
267  SHAPE_LINE_CHAIN& outline = item->GetPolygons().Outline( idx );
268  m_gal->DrawPolygon( outline );
269  }
270 }
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:175
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:71
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 273 of file ws_painter.cpp.

274 {
275  VECTOR2D position( aItem->GetTextPos().x, aItem->GetTextPos().y );
276  int penWidth = std::max( aItem->GetEffectiveTextPenWidth(),
278 
279  m_gal->Save();
280  m_gal->Translate( position );
281  m_gal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
282  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
283  m_gal->SetLineWidth( penWidth );
284  m_gal->SetTextAttributes( aItem );
285  m_gal->SetIsFill( false );
286  m_gal->SetIsStroke( true );
287  m_gal->StrokeText( aItem->GetShownText(), VECTOR2D( 0, 0 ), 0.0 );
288  m_gal->Restore();
289 }
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:174
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:157
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:71
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:248
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:134

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 292 of file ws_painter.cpp.

293 {
294  m_gal->Save();
295  auto* bitmap = static_cast<WS_DATA_ITEM_BITMAP*>( aItem->GetPeer() );
296 
297  VECTOR2D position = aItem->GetPosition();
298  m_gal->Translate( position );
299 
300  // When the image scale factor is not 1.0, we need to modify the actual scale
301  // as the image scale factor is similar to a local zoom
302  double img_scale = bitmap->m_ImageBitmap->GetScale();
303 
304  if( img_scale != 1.0 )
305  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
306 
307  m_gal->DrawBitmap( *bitmap->m_ImageBitmap );
308 
309 #if 0 // For bounding box debug purpose only
310  EDA_RECT bbox = aItem->GetBoundingBox();
311  m_gal->SetIsFill( true );
312  m_gal->SetIsStroke( true );
313  m_gal->SetFillColor( COLOR4D( 1, 1, 1, 0.4 ) );
314  m_gal->SetStrokeColor( COLOR4D( 0, 0, 0, 1 ) );
315 
316  if( img_scale != 1.0 )
317  m_gal->Scale( VECTOR2D( 1.0, 1.0 ) );
318 
319  m_gal->DrawRectangle( VECTOR2D( bbox.GetOrigin() ) - position,
320  VECTOR2D( bbox.GetEnd() ) - position );
321 #endif
322 
323  m_gal->Restore();
324 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
WS_DATA_ITEM * GetPeer() const
Definition: ws_draw_item.h:70
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.
wxPoint GetPosition() const override
Definition: ws_draw_item.h:331
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.
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:99

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 327 of file ws_painter.cpp.

328 {
329  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
330  VECTOR2D end = VECTOR2D( aItem->GetPageSize().x,
331  aItem->GetPageSize().y );
332 
333  m_gal->SetIsStroke( true );
334 
335  // Use a gray color for the border color
337  m_gal->SetIsFill( false );
338  m_gal->DrawRectangle( origin, end );
339 
340  // Draw the corner marker
341  double marker_size = aItem->GetMarkerSize();
342 
344  VECTOR2D pos = VECTOR2D( aItem->GetMarkerPos().x, aItem->GetMarkerPos().y );
345 
346  // Draw a cirle and a X
347  m_gal->DrawCircle( pos, marker_size );
348  m_gal->DrawLine( VECTOR2D( pos.x - marker_size, pos.y - marker_size),
349  VECTOR2D( pos.x + marker_size, pos.y + marker_size ) );
350  m_gal->DrawLine( VECTOR2D( pos.x + marker_size, pos.y - marker_size),
351  VECTOR2D( pos.x - marker_size, pos.y + marker_size ) );
352 }
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:253
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
double GetMarkerSize() const
Definition: ws_draw_item.h:256
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
const wxPoint & GetMarkerPos() const
Definition: ws_draw_item.h:254

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 355 of file ws_painter.cpp.

356 {
357  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
358  VECTOR2D end = VECTOR2D( aPageInfo->GetWidthMils() * aScaleFactor,
359  aPageInfo->GetHeightMils() * aScaleFactor );
360 
361  m_gal->SetIsStroke( true );
362  // Use a gray color for the border color
364  m_gal->SetIsFill( false );
365  m_gal->DrawRectangle( origin, end );
366 }
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:141
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:138

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: