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
 Function GetSettings Returns pointer to current settings that are going to be used when drawing items. More...
 
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 99 of file ws_painter.h.

Constructor & Destructor Documentation

◆ WS_PAINTER()

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

Definition at line 102 of file ws_painter.h.

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

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 112 of file ws_painter.h.

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

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

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

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

279 {
280  m_gal->SetIsStroke( true );
281  m_gal->SetIsFill( false );
282  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
283  m_gal->SetLineWidth( aItem->GetPenWidth() );
284  m_gal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
285 }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:129
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:124
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:360
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:122
int GetPenWidth() const
Definition: ws_draw_item.h:121
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
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References WS_DRAW_ITEM_LINE::GetEnd(), WS_DRAW_ITEM_LINE::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 288 of file ws_painter.cpp.

289 {
290  m_gal->SetIsStroke( true );
291  m_gal->SetIsFill( false );
292  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
293  m_gal->SetLineWidth( aItem->GetPenWidth() );
294  m_gal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
295 }
const wxPoint & GetStart() const
Definition: ws_draw_item.h:206
const wxPoint & GetEnd() const
Definition: ws_draw_item.h:208
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:129
int GetPenWidth() const
Definition: ws_draw_item.h:205
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:360
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 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
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References WS_DRAW_ITEM_RECT::GetEnd(), WS_DRAW_ITEM_RECT::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 298 of file ws_painter.cpp.

299 {
300  m_gal->SetFillColor( m_renderSettings.GetColor( aItem, aLayer ) );
301  m_gal->SetIsFill( true );
302  m_gal->SetIsStroke( false );
303 
305 
306  for( int idx = 0; idx < item->GetPolygons().OutlineCount(); ++idx )
307  {
308  SHAPE_LINE_CHAIN& outline = item->GetPolygons().Outline( idx );
309  m_gal->DrawPolygon( outline );
310  }
311 }
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:129
SHAPE_POLY_SET & GetPolygons()
Definition: ws_draw_item.h:167
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:360
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 314 of file ws_painter.cpp.

315 {
316  VECTOR2D position( aItem->GetTextPos().x, aItem->GetTextPos().y );
317 
318  m_gal->Save();
319  m_gal->Translate( position );
320  m_gal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
321  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
322  m_gal->SetLineWidth( aItem->GetThickness() );
323  m_gal->SetTextAttributes( aItem );
324  m_gal->SetIsFill( false );
325  m_gal->SetIsStroke( true );
326  m_gal->StrokeText( aItem->GetShownText(), VECTOR2D( 0, 0 ), 0.0 );
327  m_gal->Restore();
328 }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:129
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:158
int GetThickness() const
Return the pen width.
Definition: eda_text.h:148
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:360
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, int aMarkupFlags=0)
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
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
virtual wxString GetShownText() const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:129
virtual void Save()
Save the context.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References EDA_TEXT::GetShownText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetThickness(), 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 331 of file ws_painter.cpp.

332 {
333  m_gal->Save();
334  auto* bitmap = static_cast<WS_DATA_ITEM_BITMAP*>( aItem->GetPeer() );
335 
336  VECTOR2D position = aItem->GetPosition();
337  m_gal->Translate( position );
338 
339  // When the image scale factor is not 1.0, we need to modify the actual scale
340  // as the image scale factor is similar to a local zoom
341  double img_scale = bitmap->m_ImageBitmap->GetScale();
342 
343  if( img_scale != 1.0 )
344  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
345 
346  m_gal->DrawBitmap( *bitmap->m_ImageBitmap );
347 
348 #if 0 // For bounding box debug purpose only
349  EDA_RECT bbox = aItem->GetBoundingBox();
350  m_gal->SetIsFill( true );
351  m_gal->SetIsStroke( true );
352  m_gal->SetFillColor( COLOR4D( 1, 1, 1, 0.4 ) );
353  m_gal->SetStrokeColor( COLOR4D( 0, 0, 0, 1 ) );
354 
355  if( img_scale != 1.0 )
356  m_gal->Scale( VECTOR2D( 1.0, 1.0 ) );
357 
358  m_gal->DrawRectangle( VECTOR2D( bbox.GetOrigin() ) - position,
359  VECTOR2D( bbox.GetEnd() ) - position );
360 #endif
361 
362  m_gal->Restore();
363 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
WS_DATA_ITEM * GetPeer() const
Definition: ws_draw_item.h:66
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:360
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:330
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 366 of file ws_painter.cpp.

367 {
368  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
369  VECTOR2D end = VECTOR2D( aItem->GetPageSize().x,
370  aItem->GetPageSize().y );
371 
372  m_gal->SetIsStroke( true );
373 
374  // Use a gray color for the border color
376  m_gal->SetIsFill( false );
377  m_gal->DrawRectangle( origin, end );
378 
379  // Draw the corner marker
380  double marker_size = aItem->GetMarkerSize();
381 
383  VECTOR2D pos = VECTOR2D( aItem->GetMarkerPos().x, aItem->GetMarkerPos().y );
384 
385  // Draw a cirle and a X
386  m_gal->DrawCircle( pos, marker_size );
387  m_gal->DrawLine( VECTOR2D( pos.x - marker_size, pos.y - marker_size),
388  VECTOR2D( pos.x + marker_size, pos.y + marker_size ) );
389  m_gal->DrawLine( VECTOR2D( pos.x + marker_size, pos.y - marker_size),
390  VECTOR2D( pos.x - marker_size, pos.y + marker_size ) );
391 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:129
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:360
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 394 of file ws_painter.cpp.

395 {
396  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
397  VECTOR2D end = VECTOR2D( aPageInfo->GetWidthMils() * aScaleFactor,
398  aPageInfo->GetHeightMils() * aScaleFactor );
399 
400  m_gal->SetIsStroke( true );
401  // Use a gray color for the border color
403  m_gal->SetIsFill( false );
404  m_gal->DrawRectangle( origin, end );
405 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:129
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:360
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

Function GetSettings Returns pointer to current settings that are going to be used when drawing items.

Returns
Current rendering settings.

Implements KIGFX::PAINTER.

Definition at line 118 of file ws_painter.h.

118 { return &m_renderSettings; }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:129

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 328 of file painter.h.

329  {
330  m_gal = aGal;
331  }
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:360

References KIGFX::PAINTER::m_gal.

Member Data Documentation

◆ m_brightenedColor

COLOR4D KIGFX::PAINTER::m_brightenedColor
protectedinherited

Color of brightened item frame.

Definition at line 363 of file painter.h.

◆ m_gal

◆ m_renderSettings

WS_RENDER_SETTINGS KIGFX::WS_PAINTER::m_renderSettings
private

Definition at line 129 of file ws_painter.h.

Referenced by ApplySettings(), and GetSettings().


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