KiCad PCB EDA Suite
Loading...
Searching...
No Matches
router_status_view_item.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <gal/color4d.h>
22#include <kiplatform/ui.h>
23#include <layer_ids.h>
24#include <wx/settings.h>
25
28#include "gr_text.h"
29
30using namespace KIGFX;
31
32
34{
35 BOX2I tmp;
36
37 // this is an edit-time artefact; no reason to try and be smart with the bounding box
38 // (besides, we can't tell the text extents without a view to know what the scale is)
39 tmp.SetMaximum();
40 return tmp;
41}
42
44{
45 return { LAYER_UI_START, LAYER_UI_START + 1 };
46}
47
48void ROUTER_STATUS_VIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
49{
50 KIGFX::GAL* gal = aView->GetGAL();
51 bool viewFlipped = gal->IsFlippedX();
52 bool drawingDropShadows = ( aLayer == LAYER_UI_START );
53
54 gal->Save();
55 gal->Scale( { 1., 1. } );
56
60 const KIFONT::METRICS& fontMetrics = KIFONT::METRICS::Default();
61 TEXT_ATTRIBUTES textAttrs;
62 int textWidth;
63
64 textWidth = std::max( GRTextWidth( m_status, font, textDims.GlyphSize, textDims.StrokeWidth,
65 false, false, fontMetrics ),
66 GRTextWidth( m_hint, font, hintDims.GlyphSize, hintDims.StrokeWidth,
67 false, false, fontMetrics ) );
68
69 VECTOR2I margin = KiROUND( textDims.GlyphSize.x * 0.4, textDims.GlyphSize.y * 0.6 );
70 VECTOR2I size( textWidth + margin.x, KiROUND( textDims.GlyphSize.y * 1.7 ) );
71 VECTOR2I offset( margin.x * 5, -( size.y + margin.y * 5 ) );
72
73 if( !m_hint.IsEmpty() )
74 size.y += KiROUND( hintDims.GlyphSize.y * 1.2 );
75
76 if( drawingDropShadows )
77 {
78 gal->SetIsFill( true );
79 gal->SetIsStroke( true );
80 gal->SetLineWidth( gal->GetScreenWorldMatrix().GetScale().x * 2 );
81 gal->SetStrokeColor( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
82 KIGFX::COLOR4D bgColor( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
83 gal->SetFillColor( bgColor.WithAlpha( 0.9 ) );
84
85 gal->DrawRectangle( GetPosition() + offset - margin,
86 GetPosition() + offset + size + margin );
87 gal->Restore();
88 return;
89 }
90
91 COLOR4D bg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
92 COLOR4D normal = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
94
95 if( viewFlipped )
97 else
99
100 gal->SetIsFill( false );
101 gal->SetIsStroke( true );
102 gal->SetStrokeColor( normal );
103 textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
104
105 // Prevent text flipping when view is flipped
106 if( gal->IsFlippedX() )
107 {
108 textAttrs.m_Mirrored = true;
110 }
111
112 textAttrs.m_Size = textDims.GlyphSize;
113 textAttrs.m_StrokeWidth = textDims.StrokeWidth;
114
115 VECTOR2I textPos = GetPosition() + offset + margin;
116 font->Draw( gal, m_status, textPos, textAttrs, KIFONT::METRICS::Default() );
117
118 if( !m_hint.IsEmpty() )
119 {
120 textAttrs.m_Size = hintDims.GlyphSize;
121 textAttrs.m_StrokeWidth = hintDims.StrokeWidth;
122
123 textPos.y += KiROUND( textDims.GlyphSize.y * 1.6 );
124 font->Draw( gal, m_hint, textPos, textAttrs, KIFONT::METRICS::Default() );
125 }
126
127 gal->Restore();
128}
129
int red
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
constexpr void SetMaximum()
Definition box2.h:76
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:143
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr) const
Draw a string.
Definition font.cpp:246
static const METRICS & Default()
Definition font.cpp:48
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition color4d.h:308
Abstract interface for drawing on a 2D-surface.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
virtual void Restore()
Restore the context.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
virtual void Save()
Save the context.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:207
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition matrix3x3.h:291
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
Draw the parts of the object belonging to layer aLayer.
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
VECTOR2I GetPosition() const override
GR_TEXT_H_ALIGN_T m_Halign
int GRTextWidth(const wxString &aText, KIFONT::FONT *aFont, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const KIFONT::METRICS &aFontMetrics)
Definition gr_text.cpp:95
@ LAYER_UI_START
Definition layer_ids.h:355
TEXT_DIMS GetConstantGlyphHeight(KIGFX::GAL *aGal, int aRelativeSize=0)
Set the GAL glyph height to a constant scaled value, so that it always looks the same on screen.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683