From ce9b1e3da54220cc8d65967f86ee1121ca96006a Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 6 Jun 2019 11:13:10 +0200 Subject: [PATCH] Pl_editor: add missing HitTest() for WS_DRAW_ITEM_BITMAP item. --- common/page_layout/ws_draw_item.cpp | 28 ++++++++++++++++++++--- include/ws_data_item.h | 35 ++++++++++++++++------------- include/ws_draw_item.h | 2 ++ 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/common/page_layout/ws_draw_item.cpp b/common/page_layout/ws_draw_item.cpp index a898101829..7d4259842c 100644 --- a/common/page_layout/ws_draw_item.cpp +++ b/common/page_layout/ws_draw_item.cpp @@ -368,10 +368,32 @@ void WS_DRAW_ITEM_BITMAP::PrintWsItem( wxDC* aDC, const wxPoint& aOffset, COLOR4 const EDA_RECT WS_DRAW_ITEM_BITMAP::GetBoundingBox() const { auto* bitmap = static_cast( m_peer ); - EDA_RECT rect = bitmap->m_ImageBitmap->GetBoundingBox(); + wxSize bm_size = bitmap->m_ImageBitmap->GetSize(); - rect.Move( m_pos ); - return rect; + // Size is in mils, convert to iu (0.001 mm) + bm_size.x *= 25.4; + bm_size.y *= 25.4; + + EDA_RECT bbox; + bbox.SetSize( bm_size ); + bbox.SetOrigin( m_pos.x - bm_size.x/2, m_pos.y - bm_size.y/2 ); + + return bbox; +} + + +bool WS_DRAW_ITEM_BITMAP::HitTest( const wxPoint& aPosition, int aAccuracy ) const +{ + EDA_RECT bbox = GetBoundingBox(); + bbox.Inflate( aAccuracy ); + + return bbox.Contains( aPosition ); +} + + +bool WS_DRAW_ITEM_BITMAP::HitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const +{ + return WS_DRAW_ITEM_BASE::HitTest( aRect, aContains, aAccuracy ); } diff --git a/include/ws_data_item.h b/include/ws_data_item.h index ac88496e6d..763da6e7d4 100644 --- a/include/ws_data_item.h +++ b/include/ws_data_item.h @@ -40,9 +40,11 @@ class WS_DRAW_ITEM_TEXT; // Forward declaration #define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm -// A coordinate is relative to a page corner. -// Any of the 4 corners can be a reference. -// The default is the right bottom corner +/** + * A coordinate is relative to a page corner. + * Any of the 4 corners can be a reference. + * The default is the right bottom corner + */ enum CORNER_ANCHOR { RB_CORNER, // right bottom corner @@ -58,10 +60,11 @@ enum PAGE_OPTION SUBSEQUENT_PAGES }; -// a coordinate point -// The position is always relative to the corner anchor -// Note the coordinate is from the anchor point -// to the opposite corner. +/** + * A coordinate point + * The position is always relative to the corner anchor + * Note the coordinate is from the anchor point to the opposite corner. + */ class POINT_COORD { public: @@ -78,13 +81,15 @@ public: }; -// Work sheet structure type definitions. -// Basic items are: -// * segment and rect (defined by 2 points) -// * text (defined by a coordinate), the text and its justifications -// * poly polygon defined by a coordinate, and a set of list of corners -// ( because we use it for logos, there are more than one polygon -// in this description +/** + * Work sheet structure type definitions. + * Basic items are: + * * segment and rect (defined by 2 points) + * * text (defined by a coordinate), the text and its justifications + * * poly polygon defined by a coordinate, and a set of list of corners + * ( because we use it for logos, there are more than one polygon + * in this description + */ class WS_DATA_ITEM { public: @@ -295,7 +300,7 @@ class WS_DATA_ITEM_TEXT : public WS_DATA_ITEM public: wxString m_TextBase; // The basic text, with format symbols wxString m_FullText; // The expanded text, shown on screen - double m_Orient; // Orientation in degrees + double m_Orient; // Orientation in degrees EDA_TEXT_HJUSTIFY_T m_Hjustify; EDA_TEXT_VJUSTIFY_T m_Vjustify; bool m_Italic; diff --git a/include/ws_draw_item.h b/include/ws_draw_item.h index 6bce7e21a8..7a5579a417 100644 --- a/include/ws_draw_item.h +++ b/include/ws_draw_item.h @@ -287,6 +287,8 @@ public: void PrintWsItem( wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor ) override; + bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; + bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override; const EDA_RECT GetBoundingBox() const override; wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;