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 (C) 2024 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <gal/color4d.h>
26#include <kiplatform/ui.h>
27#include <layer_ids.h>
28#include <wx/settings.h>
29
32#include "gr_text.h"
33
34using namespace KIGFX;
35
36
38{
39 BOX2I tmp;
40
41 // this is an edit-time artefact; no reason to try and be smart with the bounding box
42 // (besides, we can't tell the text extents without a view to know what the scale is)
43 tmp.SetMaximum();
44 return tmp;
45}
46
47void ROUTER_STATUS_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
48{
49 aLayers[0] = LAYER_UI_START;
50 aLayers[1] = LAYER_UI_START + 1;
51 aCount = 2;
52}
53
54void ROUTER_STATUS_VIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
55{
56 KIGFX::GAL* gal = aView->GetGAL();
57 bool viewFlipped = gal->IsFlippedX();
58 bool drawingDropShadows = ( aLayer == LAYER_UI_START );
59
60 gal->Save();
61 gal->Scale( { 1., 1. } );
62
66 const KIFONT::METRICS& fontMetrics = KIFONT::METRICS::Default();
67 TEXT_ATTRIBUTES textAttrs;
68 int textWidth;
69
70 textWidth = std::max( GRTextWidth( m_status, font, textDims.GlyphSize, textDims.StrokeWidth,
71 false, false, fontMetrics ),
72 GRTextWidth( m_hint, font, hintDims.GlyphSize, hintDims.StrokeWidth,
73 false, false, fontMetrics ) );
74
75 VECTOR2I margin( KiROUND( textDims.GlyphSize.x * 0.4 ), KiROUND( textDims.GlyphSize.y * 0.6 ) );
76 VECTOR2I size( textWidth + margin.x, KiROUND( textDims.GlyphSize.y * 1.7 ) );
77 VECTOR2I offset( margin.x * 5, -( size.y + margin.y * 5 ) );
78
79 if( !m_hint.IsEmpty() )
80 size.y += KiROUND( hintDims.GlyphSize.y * 1.2 );
81
82 if( drawingDropShadows )
83 {
84 gal->SetIsFill( true );
85 gal->SetIsStroke( true );
86 gal->SetLineWidth( gal->GetScreenWorldMatrix().GetScale().x * 2 );
87 gal->SetStrokeColor( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
88 KIGFX::COLOR4D bgColor( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
89 gal->SetFillColor( bgColor.WithAlpha( 0.9 ) );
90
91 gal->DrawRectangle( GetPosition() + offset - margin,
92 GetPosition() + offset + size + margin );
93 gal->Restore();
94 return;
95 }
96
97 COLOR4D bg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
98 COLOR4D normal = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
100
101 if( viewFlipped )
103 else
104 textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
105
106 gal->SetIsFill( false );
107 gal->SetIsStroke( true );
108 gal->SetStrokeColor( normal );
109 textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
110
111 // Prevent text flipping when view is flipped
112 if( gal->IsFlippedX() )
113 {
114 textAttrs.m_Mirrored = true;
116 }
117
118 textAttrs.m_Size = textDims.GlyphSize;
119 textAttrs.m_StrokeWidth = textDims.StrokeWidth;
120
121 VECTOR2I textPos = GetPosition() + offset + margin;
122 font->Draw( gal, m_status, textPos, textAttrs, KIFONT::METRICS::Default() );
123
124 if( !m_hint.IsEmpty() )
125 {
126 textAttrs.m_Size = hintDims.GlyphSize;
127 textAttrs.m_StrokeWidth = hintDims.StrokeWidth;
128
129 textPos.y += KiROUND( textDims.GlyphSize.y * 1.6 );
130 font->Draw( gal, m_hint, textPos, textAttrs, KIFONT::METRICS::Default() );
131 }
132
133 gal->Restore();
134}
135
void SetMaximum()
Definition: box2.h:70
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:146
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
Draw a string.
Definition: font.cpp:257
static const METRICS & Default()
Definition: font.cpp:52
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:311
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:68
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:197
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:295
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
Draw the parts of the object belonging to layer aLayer.
void ViewGetLayers(int aLayers[], int &aCount) 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:113
@ LAYER_UI_START
Definition: layer_ids.h:265
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: color4d.cpp:247
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:118