2022-01-25 22:33:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2022-08-27 17:23:43 +00:00
|
|
|
#include <base_units.h>
|
2022-01-25 22:33:37 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <plotters/plotter.h>
|
|
|
|
#include <widgets/msgpanel.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <string_utils.h>
|
|
|
|
#include <schematic.h>
|
|
|
|
#include <settings/color_settings.h>
|
|
|
|
#include <sch_painter.h>
|
|
|
|
#include <dialogs/html_message_box.h>
|
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
|
|
|
#include <core/kicad_algo.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <lib_textbox.h>
|
|
|
|
|
2022-09-20 18:41:16 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
using KIGFX::SCH_RENDER_SETTINGS;
|
|
|
|
|
|
|
|
|
|
|
|
LIB_TEXTBOX::LIB_TEXTBOX( LIB_SYMBOL* aParent, int aLineWidth, FILL_T aFillType,
|
|
|
|
const wxString& text ) :
|
|
|
|
LIB_SHAPE( aParent, SHAPE_T::RECT, aLineWidth, aFillType, LIB_TEXTBOX_T ),
|
2022-09-16 04:38:10 +00:00
|
|
|
EDA_TEXT( schIUScale, text )
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
SetTextSize( VECTOR2I( schIUScale.MilsToIU( DEFAULT_TEXT_SIZE ),
|
|
|
|
schIUScale.MilsToIU( DEFAULT_TEXT_SIZE ) ) );
|
2022-01-25 22:33:37 +00:00
|
|
|
SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
|
|
|
SetMultilineAllowed( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LIB_TEXTBOX::LIB_TEXTBOX( const LIB_TEXTBOX& aText ) :
|
|
|
|
LIB_SHAPE( aText ),
|
|
|
|
EDA_TEXT( aText )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
int LIB_TEXTBOX::GetTextMargin() const
|
|
|
|
{
|
|
|
|
return KiROUND( GetTextSize().y * 0.8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TEXTBOX::MirrorHorizontally( const VECTOR2I& center )
|
|
|
|
{
|
|
|
|
// Text is NOT really mirrored; it just has its justification flipped
|
|
|
|
if( GetTextAngle() == ANGLE_HORIZONTAL )
|
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
switch( GetHorizJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT: SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER: break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); break;
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TEXTBOX::MirrorVertically( const VECTOR2I& center )
|
|
|
|
{
|
|
|
|
// Text is NOT really mirrored; it just has its justification flipped
|
|
|
|
if( GetTextAngle() == ANGLE_VERTICAL )
|
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
switch( GetHorizJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT: SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER: break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); break;
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TEXTBOX::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
|
|
|
|
{
|
|
|
|
LIB_SHAPE::Rotate( aCenter, aRotateCCW );
|
|
|
|
SetTextAngle( GetTextAngle() == ANGLE_VERTICAL ? ANGLE_HORIZONTAL : ANGLE_VERTICAL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
VECTOR2I LIB_TEXTBOX::GetDrawPos() const
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
|
|
|
int margin = GetTextMargin();
|
|
|
|
BOX2I bbox( VECTOR2I( std::min( m_start.x, m_end.x ), std::min( -m_start.y, -m_end.y ) ),
|
|
|
|
VECTOR2I( abs( m_end.x - m_start.x ), abs( m_end.y - m_start.y ) ) );
|
|
|
|
|
2022-09-02 18:15:40 +00:00
|
|
|
VECTOR2I pos( bbox.GetLeft() + margin, bbox.GetBottom() - margin );
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
if( GetTextAngle() == ANGLE_VERTICAL )
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
switch( GetHorizJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT:
|
2022-09-02 18:15:40 +00:00
|
|
|
pos.y = bbox.GetBottom() - margin;
|
|
|
|
break;
|
2022-01-31 19:11:21 +00:00
|
|
|
case GR_TEXT_H_ALIGN_CENTER:
|
2022-09-02 18:15:40 +00:00
|
|
|
pos.y = ( bbox.GetTop() + bbox.GetBottom() ) / 2;
|
|
|
|
break;
|
2022-01-31 19:11:21 +00:00
|
|
|
case GR_TEXT_H_ALIGN_RIGHT:
|
2022-09-02 18:15:40 +00:00
|
|
|
pos.y = bbox.GetTop() + margin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( GetVertJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_V_ALIGN_TOP:
|
|
|
|
pos.x = bbox.GetLeft() + margin;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER:
|
|
|
|
pos.x = ( bbox.GetLeft() + bbox.GetRight() ) / 2;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM:
|
|
|
|
pos.x = bbox.GetRight() - margin;
|
|
|
|
break;
|
2022-01-31 19:11:21 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
switch( GetHorizJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT:
|
2022-09-02 18:15:40 +00:00
|
|
|
pos.x = bbox.GetLeft() + margin;
|
|
|
|
break;
|
2022-01-31 19:11:21 +00:00
|
|
|
case GR_TEXT_H_ALIGN_CENTER:
|
2022-09-02 18:15:40 +00:00
|
|
|
pos.x = ( bbox.GetLeft() + bbox.GetRight() ) / 2;
|
|
|
|
break;
|
2022-01-31 19:11:21 +00:00
|
|
|
case GR_TEXT_H_ALIGN_RIGHT:
|
2022-09-02 18:15:40 +00:00
|
|
|
pos.x = bbox.GetRight() - margin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( GetVertJustify() )
|
|
|
|
{
|
|
|
|
case GR_TEXT_V_ALIGN_TOP:
|
|
|
|
pos.y = bbox.GetTop() + margin;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER:
|
|
|
|
pos.y = ( bbox.GetTop() + bbox.GetBottom() ) / 2;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM:
|
|
|
|
pos.y = bbox.GetBottom() - margin;
|
|
|
|
break;
|
2022-01-31 19:11:21 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2022-02-01 00:26:37 +00:00
|
|
|
|
2022-09-02 18:15:40 +00:00
|
|
|
return pos;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-03 12:20:30 +00:00
|
|
|
int LIB_TEXTBOX::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aOther.Type() == LIB_TEXTBOX_T );
|
|
|
|
|
|
|
|
int retv = LIB_ITEM::compare( aOther, aCompareFlags );
|
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
const LIB_TEXTBOX* tmp = static_cast<const LIB_TEXTBOX*>( &aOther );
|
|
|
|
|
|
|
|
int result = GetText().CmpNoCase( tmp->GetText() );
|
|
|
|
|
|
|
|
if( result != 0 )
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if( GetTextWidth() != tmp->GetTextWidth() )
|
|
|
|
return GetTextWidth() - tmp->GetTextWidth();
|
|
|
|
|
|
|
|
if( GetTextHeight() != tmp->GetTextHeight() )
|
|
|
|
return GetTextHeight() - tmp->GetTextHeight();
|
|
|
|
|
|
|
|
if( IsBold() != tmp->IsBold() )
|
|
|
|
return IsBold() - tmp->IsBold();
|
|
|
|
|
|
|
|
if( IsItalic() != tmp->IsItalic() )
|
|
|
|
return IsItalic() - tmp->IsItalic();
|
|
|
|
|
|
|
|
if( GetHorizJustify() != tmp->GetHorizJustify() )
|
|
|
|
return GetHorizJustify() - tmp->GetHorizJustify();
|
|
|
|
|
|
|
|
if( GetTextAngle().AsTenthsOfADegree() != tmp->GetTextAngle().AsTenthsOfADegree() )
|
|
|
|
return GetTextAngle().AsTenthsOfADegree() - tmp->GetTextAngle().AsTenthsOfADegree();
|
|
|
|
|
|
|
|
return EDA_SHAPE::Compare( &static_cast<const LIB_SHAPE&>( aOther ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* LIB_TEXTBOX::getDrawFont() const
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
|
|
|
KIFONT::FONT* font = EDA_TEXT::GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
|
2022-09-16 16:20:36 +00:00
|
|
|
const TRANSFORM& aTransform, bool aDimmed )
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
if( IsPrivate() )
|
|
|
|
return;
|
|
|
|
|
2022-04-29 12:51:49 +00:00
|
|
|
bool forceNoFill = static_cast<bool>( aData );
|
|
|
|
bool blackAndWhiteMode = GetGRForceBlackPenState();
|
|
|
|
int penWidth = GetEffectivePenWidth( aSettings );
|
|
|
|
COLOR4D color = GetStroke().GetColor();
|
|
|
|
PLOT_DASH_TYPE lineStyle = GetStroke().GetPlotStyle();
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
|
|
|
VECTOR2I pt1 = aTransform.TransformCoordinate( m_start ) + aOffset;
|
|
|
|
VECTOR2I pt2 = aTransform.TransformCoordinate( m_end ) + aOffset;
|
|
|
|
|
2022-04-01 20:23:38 +00:00
|
|
|
if( !forceNoFill && GetFillMode() == FILL_T::FILLED_WITH_COLOR && !blackAndWhiteMode )
|
2022-04-29 12:51:49 +00:00
|
|
|
GRFilledRect( DC, pt1, pt2, penWidth, GetFillColor(), GetFillColor() );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
if( penWidth > 0 )
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
penWidth = std::max( penWidth, aSettings->GetMinPenWidth() );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-04-29 12:51:49 +00:00
|
|
|
if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( LAYER_DEVICE );
|
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
COLOR4D bg = aSettings->GetBackgroundColor();
|
|
|
|
|
|
|
|
if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
|
|
|
|
bg = COLOR4D::WHITE;
|
|
|
|
|
|
|
|
if( aDimmed )
|
2023-01-11 20:53:09 +00:00
|
|
|
{
|
|
|
|
color.Desaturate( );
|
2022-09-16 16:20:36 +00:00
|
|
|
color = color.Mix( bg, 0.5f );
|
2023-01-11 20:53:09 +00:00
|
|
|
}
|
2022-09-16 16:20:36 +00:00
|
|
|
|
2022-04-29 12:51:49 +00:00
|
|
|
if( lineStyle == PLOT_DASH_TYPE::DEFAULT )
|
2022-09-02 18:15:40 +00:00
|
|
|
lineStyle = PLOT_DASH_TYPE::SOLID;
|
2022-04-29 12:51:49 +00:00
|
|
|
|
|
|
|
if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE )
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
2022-01-31 19:11:21 +00:00
|
|
|
GRRect( DC, pt1, pt2, penWidth, color );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<SHAPE*> shapes = MakeEffectiveShapes( true );
|
|
|
|
|
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
{
|
2022-04-29 12:51:49 +00:00
|
|
|
STROKE_PARAMS::Stroke( shape, lineStyle, penWidth, aSettings,
|
2022-01-31 19:11:21 +00:00
|
|
|
[&]( const VECTOR2I& a, const VECTOR2I& b )
|
|
|
|
{
|
2022-06-24 15:07:22 +00:00
|
|
|
VECTOR2I pts = aTransform.TransformCoordinate( a ) + aOffset;
|
|
|
|
VECTOR2I pte = aTransform.TransformCoordinate( b ) + aOffset;
|
|
|
|
GRLine( DC, pts.x, pts.y, pte.x, pte.y, penWidth, color );
|
2022-01-31 19:11:21 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
delete shape;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
LIB_TEXTBOX text( *this );
|
|
|
|
|
2022-04-29 12:51:49 +00:00
|
|
|
color = GetTextColor();
|
|
|
|
|
|
|
|
if( blackAndWhiteMode || color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( LAYER_DEVICE );
|
2022-04-27 21:45:22 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
COLOR4D bg = aSettings->GetBackgroundColor();
|
|
|
|
|
|
|
|
if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
|
|
|
|
bg = COLOR4D::WHITE;
|
|
|
|
|
|
|
|
if( aDimmed )
|
2023-01-11 20:53:09 +00:00
|
|
|
{
|
|
|
|
color.Desaturate( );
|
2022-09-16 16:20:36 +00:00
|
|
|
color = color.Mix( bg, 0.5f );
|
2023-01-11 20:53:09 +00:00
|
|
|
}
|
2022-09-16 16:20:36 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetMinPenWidth() );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
if( aTransform.y1 )
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
text.SetTextAngle( text.GetTextAngle() == ANGLE_HORIZONTAL ? ANGLE_VERTICAL
|
|
|
|
: ANGLE_HORIZONTAL );
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* font = GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
// NB: GetDrawPos() will want Symbol Editor (upside-down) coordinates
|
2022-01-28 22:51:34 +00:00
|
|
|
text.SetStart( VECTOR2I( pt1.x, -pt1.y ) );
|
|
|
|
text.SetEnd( VECTOR2I( pt2.x, -pt2.y ) );
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
GRPrintText( DC, text.GetDrawPos(), color, text.GetShownText( true ), text.GetTextAngle(),
|
2022-01-28 22:51:34 +00:00
|
|
|
text.GetTextSize(), text.GetHorizJustify(), text.GetVertJustify(), penWidth,
|
2022-10-22 20:32:10 +00:00
|
|
|
text.IsItalic(), text.IsBold(), font );
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString LIB_TEXTBOX::GetShownText( bool aAllowExtraText, int aDepth ) const
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* font = GetFont();
|
2022-01-25 22:33:37 +00:00
|
|
|
VECTOR2D size = GetEnd() - GetStart();
|
|
|
|
int colWidth = GetTextAngle() == ANGLE_HORIZONTAL ? size.x : size.y;
|
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
colWidth = abs( colWidth ) - GetTextMargin() * 2;
|
|
|
|
font->LinebreakText( text, colWidth, GetTextSize(), GetTextThickness(), IsBold(), IsItalic() );
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LIB_TEXTBOX::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
|
|
|
{
|
2022-09-16 23:42:20 +00:00
|
|
|
if( aAccuracy < schIUScale.MilsToIU( MINIMUM_SELECTION_DISTANCE ) )
|
|
|
|
aAccuracy = schIUScale.MilsToIU( MINIMUM_SELECTION_DISTANCE );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I rect = GetBoundingBox();
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
return rect.Contains( aPosition );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool LIB_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I rect = aRect;
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return rect.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString LIB_TEXTBOX::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
|
|
|
return wxString::Format( _( "Graphic Text Box" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BITMAPS LIB_TEXTBOX::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return BITMAPS::add_textbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
|
2022-09-16 16:20:36 +00:00
|
|
|
const TRANSFORM& aTransform, bool aDimmed ) const
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aPlotter != nullptr );
|
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
if( IsPrivate() )
|
|
|
|
return;
|
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
if( aBackground )
|
|
|
|
{
|
2022-09-16 16:20:36 +00:00
|
|
|
LIB_SHAPE::Plot( aPlotter, aBackground, aOffset, aTransform, aDimmed );
|
2022-02-10 19:49:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
RENDER_SETTINGS* renderSettings = aPlotter->RenderSettings();
|
|
|
|
VECTOR2I start = aTransform.TransformCoordinate( m_start ) + aOffset;
|
|
|
|
VECTOR2I end = aTransform.TransformCoordinate( m_end ) + aOffset;
|
|
|
|
COLOR4D bg = renderSettings->GetBackgroundColor();
|
2022-10-21 21:28:31 +00:00
|
|
|
|
|
|
|
if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
|
|
|
|
bg = COLOR4D::WHITE;
|
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
int penWidth = GetEffectivePenWidth( renderSettings );
|
2022-04-29 12:51:49 +00:00
|
|
|
COLOR4D color = GetStroke().GetColor();
|
|
|
|
PLOT_DASH_TYPE lineStyle = GetStroke().GetPlotStyle();
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
if( penWidth > 0 )
|
|
|
|
{
|
2022-06-08 22:52:44 +00:00
|
|
|
if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
|
2022-10-22 20:32:10 +00:00
|
|
|
color = renderSettings->GetLayerColor( LAYER_DEVICE );
|
2022-03-30 19:37:56 +00:00
|
|
|
|
2022-04-29 12:51:49 +00:00
|
|
|
if( lineStyle == PLOT_DASH_TYPE::DEFAULT )
|
|
|
|
lineStyle = PLOT_DASH_TYPE::DASH;
|
|
|
|
|
2022-10-21 21:28:31 +00:00
|
|
|
if( aDimmed )
|
2023-01-11 20:53:09 +00:00
|
|
|
{
|
|
|
|
color.Desaturate( );
|
2022-10-21 21:28:31 +00:00
|
|
|
color = color.Mix( bg, 0.5f );
|
2023-01-11 20:53:09 +00:00
|
|
|
}
|
2022-10-21 21:28:31 +00:00
|
|
|
|
2022-04-29 12:51:49 +00:00
|
|
|
aPlotter->SetColor( color );
|
2022-06-28 18:06:17 +00:00
|
|
|
aPlotter->SetDash( penWidth, lineStyle );
|
2022-01-31 19:11:21 +00:00
|
|
|
aPlotter->Rect( start, end, FILL_T::NO_FILL, penWidth );
|
2022-06-28 18:06:17 +00:00
|
|
|
aPlotter->SetDash( penWidth, PLOT_DASH_TYPE::SOLID );
|
2022-01-31 19:11:21 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* font = GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() );
|
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
LIB_TEXTBOX text( *this );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-04-29 12:51:49 +00:00
|
|
|
color = GetTextColor();
|
|
|
|
|
|
|
|
if( !aPlotter->GetColorMode() || color == COLOR4D::UNSPECIFIED )
|
2022-10-22 20:32:10 +00:00
|
|
|
color = renderSettings->GetLayerColor( LAYER_DEVICE );
|
2022-04-27 21:45:22 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
if( aDimmed )
|
2023-01-11 20:53:09 +00:00
|
|
|
{
|
|
|
|
color.Desaturate( );
|
2022-09-16 16:20:36 +00:00
|
|
|
color = color.Mix( bg, 0.5f );
|
2023-01-11 20:53:09 +00:00
|
|
|
}
|
2022-09-16 16:20:36 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
penWidth = std::max( GetEffectiveTextPenWidth(), aPlotter->RenderSettings()->GetMinPenWidth() );
|
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
if( aTransform.y1 )
|
2022-01-25 22:33:37 +00:00
|
|
|
{
|
|
|
|
text.SetTextAngle( text.GetTextAngle() == ANGLE_HORIZONTAL ? ANGLE_VERTICAL
|
|
|
|
: ANGLE_HORIZONTAL );
|
|
|
|
}
|
|
|
|
|
2022-01-31 19:11:21 +00:00
|
|
|
// NB: GetDrawPos() will want Symbol Editor (upside-down) coordinates
|
2022-01-25 22:33:37 +00:00
|
|
|
text.SetStart( VECTOR2I( start.x, -start.y ) );
|
|
|
|
text.SetEnd( VECTOR2I( end.x, -end.y ) );
|
|
|
|
|
|
|
|
std::vector<VECTOR2I> positions;
|
|
|
|
wxArrayString strings_list;
|
2023-05-05 13:21:56 +00:00
|
|
|
wxStringSplit( GetShownText( true ), strings_list, '\n' );
|
2022-01-25 22:33:37 +00:00
|
|
|
positions.reserve( strings_list.Count() );
|
|
|
|
|
|
|
|
text.GetLinePositions( positions, (int) strings_list.Count() );
|
|
|
|
|
2023-02-24 08:44:25 +00:00
|
|
|
TEXT_ATTRIBUTES attrs = GetAttributes();
|
|
|
|
attrs.m_StrokeWidth = penWidth;
|
|
|
|
attrs.m_Multiline = false;
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
|
|
|
|
{
|
2023-02-24 08:44:25 +00:00
|
|
|
aPlotter->PlotText( positions[ii], color, strings_list.Item( ii ), attrs, font );
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
|
|
|
// Don't use GetShownText() here; we want to show the user the variable references
|
2022-08-22 16:39:19 +00:00
|
|
|
aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
|
2022-04-26 17:52:53 +00:00
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) };
|
|
|
|
int style = IsBold() && IsItalic() ? 3 : IsBold() ? 2 : IsItalic() ? 1 : 0;
|
|
|
|
aList.emplace_back( _( "Style" ), textStyle[style] );
|
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
|
2022-03-20 15:57:18 +00:00
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
aList.emplace_back( _( "Box Width" ),
|
|
|
|
aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
|
2022-03-20 15:57:18 +00:00
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
aList.emplace_back( _( "Box Height" ),
|
|
|
|
aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
|
2022-03-20 15:57:18 +00:00
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
m_stroke.GetMsgPanelInfo( aFrame, aList );
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TEXTBOX::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aCount = 3;
|
2022-07-07 04:51:23 +00:00
|
|
|
aLayers[0] = IsPrivate() ? LAYER_PRIVATE_NOTES : LAYER_DEVICE;
|
2022-01-25 22:33:37 +00:00
|
|
|
aLayers[1] = IsPrivate() ? LAYER_NOTES_BACKGROUND : LAYER_DEVICE_BACKGROUND;
|
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
|
|
|
}
|