59 if( aDrawingDropShadows )
81 static std::vector<TICK_FORMAT> tickFormats =
99 const auto pixelSpace = aTickSpace * aScale;
104 tickFormat = ( tickFormat + 1 ) % tickFormats.size();
105 aTickSpace *= tickFormats[tickFormat].divisionBase;
108 return tickFormats[tickFormat];
126 bool aDrawingDropShadows )
141 if( !( rulerLen > 0.0 ) || !( tickSpace > 0.0 ) || !std::isfinite( rulerLen )
142 || !std::isfinite( tickSpace ) )
149 [](
double aValue ) -> int64_t
151 constexpr double lo =
static_cast<double>( std::numeric_limits<int64_t>::min() );
152 constexpr double hi =
static_cast<double>( std::numeric_limits<int64_t>::max() );
155 return std::numeric_limits<int64_t>::min();
158 return std::numeric_limits<int64_t>::max();
160 return static_cast<int64_t
>( aValue );
163 const int64_t lastRulerTick = std::max<int64_t>( 0, toTick( std::ceil( rulerLen / tickSpace ) ) - 1 );
168 VECTOR2D labelOffset = tickLine.Resize( majorTickLen );
172 double shadowXoffset = 0.0;
174 if( aDrawingDropShadows )
183 const double adjust = 1.2;
184 shadowXoffset *= adjust;
189 labelOffset = -labelOffset;
190 shadowXoffset = -shadowXoffset;
201 labelAttrs.
m_Angle = labelAngle;
218 viewportD.
Inflate( majorTickLen * 2 );
224 const VECTOR2D unitLine = aLine / rulerLen;
226 const double halfWidth = viewportD.
GetWidth() / 2;
227 const double halfHeight = viewportD.
GetHeight() / 2;
228 const double centerProj = (
center - aOrigin ).Dot( unitLine );
229 const double halfProj =
std::abs( halfWidth * unitLine.
x ) +
std::abs( halfHeight * unitLine.
y );
230 const double minProj = centerProj - halfProj;
231 const double maxProj = centerProj + halfProj;
234 if( !std::isfinite( minProj ) || !std::isfinite( maxProj ) )
238 const int64_t minTick = toTick( std::floor( minProj / tickSpace ) );
239 const int64_t maxTick = toTick( std::ceil( maxProj / tickSpace ) );
240 const int64_t firstTick = std::max<int64_t>( 0, minTick > std::numeric_limits<int64_t>::min()
241 ? minTick - 1 : minTick );
242 const int64_t lastTick = std::min<int64_t>( lastRulerTick,
243 maxTick < std::numeric_limits<int64_t>::max()
244 ? maxTick + 1 : maxTick );
246 if( firstTick > lastTick )
251 const VECTOR2D tickDir = tickLine / rulerLen;
253 for( int64_t i = firstTick; i <= lastTick; ++i )
255 const VECTOR2D tickPos = aOrigin + unitLine * ( tickSpace * i );
257 double length = aMinorTickLen;
258 bool drawLabel =
false;
272 gal->
DrawLine( tickPos, tickPos + tickDir * ( length * isign ) );
276 wxString label =
DimensionLabel(
"", tickSpace * i, aIuScale, aUnits,
false );
294 double aTickLen,
int aNumDivisions,
bool aDrawingDropShadows )
298 const double backTickSpace = aLine.
EuclideanNorm() / aNumDivisions;
303 backTickVec = backTickVec.
Resize( aTickLen * isign );
306 viewportD.
Inflate( aTickLen * 4 );
309 for(
int i = 0; i < aNumDivisions + 1; ++i )
311 const VECTOR2D backTickPos = aOrigin + aLine.
Resize( backTickSpace * i );
313 if( !viewportD.
Contains( backTickPos ) )
317 gal->
DrawLine( backTickPos, backTickPos + backTickVec );
323 EDA_UNITS userUnits,
bool aFlipX,
bool aFlipY )
376 if( drawingDropShadows )
393 int prefX = rulerVec.
y < 0.0 ? -1 : 1;
394 int prefY = rulerVec.
x < 0.0 ? 1 : -1;
402 for(
const wxString& s : cursorStrings )
406 width = std::max( width, (
double) extents.
x );
409 double height = dims.
LinePitch * cursorStrings.size();
414 double offsetX = 15.0;
418 [&](
int sx,
int sy )
421 double xStart = cursorScreen.
x + ( sx < 0 ? offsetX : -offsetX );
436 bottom = cursorScreen.
y - offsetY;
441 top = cursorScreen.
y + offsetY;
445 return left >= 0 &&
right <= screenSize.
x &&
top >= 0 && bottom <= screenSize.
y;
448 std::vector<VECTOR2I>
candidates = { { prefX, prefY }, { -prefX, prefY },
449 { prefX, -prefY }, { -prefX, -prefY } };
452 double bestDot = -1.0;
456 double dot = c.x * prefX + c.y * prefY;
458 if( dot >= 0 && fits( c.x, c.y ) )
478 drawBacksideTicks( aView, origin, rulerVec, majorTickLen, 2, drawingDropShadows );
486 arrowHead = arrowHead.
Resize( majorTickLen );
490 arrowHead = rulerVec;
492 arrowHead = arrowHead.
Resize( majorTickLen );
515 wxArrayString cursorStrings;
525 return cursorStrings;
constexpr void SetMaximum()
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr size_type GetWidth() const
constexpr Vec Centre() const
constexpr size_type GetHeight() const
constexpr bool Contains(const Vec &aPoint) const
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
EDA_ANGLE GetAngle() const
FONT is an abstract base class for both outline and stroke fonts.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
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.
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
static const METRICS & Default()
Attribute save/restore for GAL attributes.
Abstract interface for drawing on a 2D-surface.
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
VECTOR2D ToScreen(const VECTOR2D &aPoint) const
Compute the point position in screen coordinates from given world coordinates.
const COLOR4D & GetStrokeColor() const
Get the stroke color.
void ResetTextAttributes()
Reset text attributes to default styling.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
void SetTextMirrored(const bool aMirrored)
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual bool IsCairoEngine()
Return true if the GAL engine is a Cairo based type.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
double GetMinDepth() const
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
double GetWorldScale() const
Get the world scale.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
RULER_ITEM(const TWO_POINT_GEOMETRY_MANAGER &m_geomMgr, const EDA_IU_SCALE &aIuScale, EDA_UNITS userUnits, bool aFlipX, bool aFlipY)
const TWO_POINT_GEOMETRY_MANAGER & m_geomMgr
wxArrayString GetDimensionStrings() const
Get the strings for the dimensions of the ruler.
std::optional< COLOR4D > m_color
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override final
Draw the parts of the object belonging to layer aLayer.
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
const EDA_IU_SCALE & m_iuScale
Represent a very simple geometry manager for items that have a start and end point.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
bool IsMirroredX() const
Return true if view is flipped across the X axis.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
GR_TEXT_H_ALIGN_T m_Halign
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_180
@ LAYER_GP_OVERLAY
General purpose overlay.
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc).
@ LAYER_SELECT_OVERLAY
Selected items overlay.
KICOMMON_API bool IsImperialUnit(EDA_UNITS aUnit)
COLOR4D GetShadowColor(const COLOR4D &aColor)
void DrawTextNextToCursor(KIGFX::VIEW *aView, const VECTOR2D &aCursorPos, const VECTOR2D &aTextQuadrant, const wxArrayString &aStrings, bool aDrawingDropShadows)
Draw strings next to the cursor.
wxString DimensionLabel(const wxString &prefix, double aVal, const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, bool aIncludeUnits=true)
Get a formatted string showing a dimension to a sane precision with an optional prefix and unit suffi...
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.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
static double getTickLineWidth(const TEXT_DIMS &textDims, bool aDrawingDropShadows)
static const double maxTickDensity
static TICK_FORMAT getTickFormatForScale(double aScale, double &aTickSpace, EDA_UNITS aUnits)
void drawBacksideTicks(KIGFX::VIEW *aView, const VECTOR2D &aOrigin, const VECTOR2D &aLine, double aTickLen, int aNumDivisions, bool aDrawingDropShadows)
Draw simple ticks on the back of a line such that the line is divided into n parts.
void drawTicksAlongLine(KIGFX::VIEW *aView, const VECTOR2D &aOrigin, const VECTOR2D &aLine, double aMinorTickLen, const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, bool aDrawingDropShadows)
Draw labeled ticks on a line.
static const double majorTickLengthFactor
static int getShadowLayer(KIGFX::GAL *aGal)
static const double midTickLengthFactor
KIBIS top(path, &reporter)
static std::vector< int > candidates(const SEGMENT_INDEX &aIndex, const SEG &aQuery, int aPadding)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
@ NOT_USED
the 3d code uses this value
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D