KiCad PCB EDA Suite
KIGFX::WS_PAINTER Class Reference

Class 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

Class WS_PAINTER Contains methods for drawing worksheet items.

Definition at line 95 of file ws_painter.h.

Constructor & Destructor Documentation

◆ WS_PAINTER()

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

Definition at line 98 of file ws_painter.h.

98  :
99  PAINTER( aGal )
100  { }
PAINTER(GAL *aGal)
Constructor PAINTER( GAL* ) initializes this object for painting on any of the polymorphic GRAPHICS_A...
Definition: painter.cpp:67

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

109  {
110  m_renderSettings = *static_cast<const WS_RENDER_SETTINGS*>( aSettings );
111  }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:125

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

245 {
246  auto item = static_cast<const EDA_ITEM*>( aItem );
247 
248  switch( item->Type() )
249  {
250  case WSG_LINE_T: draw( (WS_DRAW_ITEM_LINE*) item, aLayer ); break;
251  case WSG_POLY_T: draw( (WS_DRAW_ITEM_POLYPOLYGONS*) item, aLayer ); break;
252  case WSG_RECT_T: draw( (WS_DRAW_ITEM_RECT*) item, aLayer ); break;
253  case WSG_TEXT_T: draw( (WS_DRAW_ITEM_TEXT*) item, aLayer ); break;
254  case WSG_BITMAP_T: draw( (WS_DRAW_ITEM_BITMAP*) item, aLayer ); break;
255  case WSG_PAGE_T: draw( (WS_DRAW_ITEM_PAGE*) item, aLayer ); break;
256  default: return false;
257  }
258 
259  return true;
260 }
void draw(const WS_DRAW_ITEM_LINE *aItem, int aLayer) const
Definition: ws_painter.cpp:263

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

264 {
265  m_gal->SetIsStroke( true );
266  m_gal->SetIsFill( false );
267  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
268  m_gal->SetLineWidth( aItem->GetPenWidth() );
269  m_gal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
270 }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:125
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:365
virtual void SetLineWidth(float aLineWidth)
Set the line width.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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:55
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 273 of file ws_painter.cpp.

274 {
275  m_gal->SetIsStroke( true );
276  m_gal->SetIsFill( false );
277  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
278  m_gal->SetLineWidth( aItem->GetPenWidth() );
279  m_gal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
280 }
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:125
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:365
virtual void SetLineWidth(float aLineWidth)
Set the line width.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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:55
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 283 of file ws_painter.cpp.

284 {
285  m_gal->SetFillColor( m_renderSettings.GetColor( aItem, aLayer ) );
286  m_gal->SetIsFill( true );
287  m_gal->SetIsStroke( false );
288 
290 
291  for( int idx = 0; idx < item->GetPolygons().OutlineCount(); ++idx )
292  {
293  SHAPE_LINE_CHAIN& outline = item->GetPolygons().Outline( idx );
294  m_gal->DrawPolygon( outline );
295  }
296 }
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:125
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:365
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.
Class 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:55
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 299 of file ws_painter.cpp.

300 {
301  VECTOR2D position( aItem->GetTextPos().x, aItem->GetTextPos().y );
302 
303  m_gal->Save();
304  m_gal->Translate( position );
305  m_gal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
306  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
307  m_gal->SetLineWidth( aItem->GetThickness() );
308  m_gal->SetTextAttributes( aItem );
309  m_gal->SetIsFill( false );
310  m_gal->SetIsStroke( true );
311  m_gal->StrokeText( aItem->GetShownText(), VECTOR2D( 0, 0 ), 0.0 );
312  m_gal->Restore();
313 }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:125
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
Function GetThickness returns 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:365
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void Rotate(double aAngle)
Rotate the context.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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:55
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
virtual wxString GetShownText() const
Returns 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(), and VECTOR2< T >::Rotate().

◆ draw() [5/6]

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

Definition at line 316 of file ws_painter.cpp.

317 {
318  m_gal->Save();
319  VECTOR2D position = aItem->GetPosition();
320  m_gal->Translate( position );
321  auto* bitmap = static_cast<WS_DATA_ITEM_BITMAP*>( aItem->GetPeer() );
322 
323  // When the image scale factor is not 1.0, we need to modify the actual scale
324  // as the image scale factor is similar to a local zoom
325  double img_scale = bitmap->m_ImageBitmap->GetScale();
326 
327  if( img_scale != 1.0 )
328  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
329 
330  m_gal->DrawBitmap( *bitmap->m_ImageBitmap );
331  m_gal->Restore();
332 }
WS_DATA_ITEM * GetPeer() const
Definition: ws_draw_item.h:66
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:365
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
virtual void Restore()
Restore the context.
const wxPoint GetPosition() const override
Definition: ws_draw_item.h:330
virtual void Save()
Save the context.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.

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

336 {
337  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
338  VECTOR2D end = VECTOR2D( aItem->GetPageSize().x,
339  aItem->GetPageSize().y );
340 
341  m_gal->SetIsStroke( true );
342 
343  // Use a gray color for the border color
344  m_gal->SetStrokeColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
345  m_gal->SetIsFill( false );
346  m_gal->DrawRectangle( origin, end );
347 
348  // Draw the corner marker
349  double marker_size = aItem->GetMarkerSize();
350 
351  m_gal->SetStrokeColor( COLOR4D( 0.4, 0.4, 1.0, 1.0 ) );
352  VECTOR2D pos = VECTOR2D( aItem->GetMarkerPos().x, aItem->GetMarkerPos().y );
353 
354  // Draw a cirle and a X
355  m_gal->DrawCircle( pos, marker_size );
356  m_gal->DrawLine( VECTOR2D( pos.x - marker_size, pos.y - marker_size),
357  VECTOR2D( pos.x + marker_size, pos.y + marker_size ) );
358  m_gal->DrawLine( VECTOR2D( pos.x + marker_size, pos.y - marker_size),
359  VECTOR2D( pos.x - marker_size, pos.y + marker_size ) );
360 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
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:365
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

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

◆ DrawBorder()

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

Definition at line 363 of file ws_painter.cpp.

364 {
365  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
366  VECTOR2D end = VECTOR2D( aPageInfo->GetWidthMils() * aScaleFactor,
367  aPageInfo->GetHeightMils() * aScaleFactor );
368 
369  m_gal->SetIsStroke( true );
370  // Use a gray color for the border color
371  m_gal->SetStrokeColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
372  m_gal->SetIsFill( false );
373  m_gal->DrawRectangle( origin, end );
374 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
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:365
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

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

114 { return &m_renderSettings; }
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:125

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

334  {
335  m_gal = aGal;
336  }
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:365

References KIGFX::PAINTER::m_gal.

Member Data Documentation

◆ m_brightenedColor

COLOR4D KIGFX::PAINTER::m_brightenedColor
protectedinherited

Color of brightened item frame.

Definition at line 368 of file painter.h.

◆ m_gal

◆ m_renderSettings

WS_RENDER_SETTINGS KIGFX::WS_PAINTER::m_renderSettings
private

Definition at line 125 of file ws_painter.h.

Referenced by ApplySettings(), and GetSettings().


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