From a6d10d6e282b42111a22fbd0be9f13a0f9e37a17 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 19 Aug 2018 20:49:35 +0100 Subject: [PATCH] Constant-size page layout object handles w/respect to zoom. Fixes: lp:1787491 * https://bugs.launchpad.net/kicad/+bug/1787491 --- .../page_layout/page_layout_graphic_items.cpp | 50 +++++++++---------- include/worksheet_dataitem.h | 10 +++- include/worksheet_shape_builder.h | 20 ++++---- pagelayout_editor/hotkeys.cpp | 2 +- pagelayout_editor/onleftclick.cpp | 2 +- pagelayout_editor/onrightclick.cpp | 4 +- pagelayout_editor/pl_editor_frame.cpp | 4 +- pagelayout_editor/pl_editor_frame.h | 2 +- 8 files changed, 51 insertions(+), 43 deletions(-) diff --git a/common/page_layout/page_layout_graphic_items.cpp b/common/page_layout/page_layout_graphic_items.cpp index e7189c80f6..d4bbb6470d 100644 --- a/common/page_layout/page_layout_graphic_items.cpp +++ b/common/page_layout/page_layout_graphic_items.cpp @@ -101,7 +101,7 @@ void WS_DRAW_ITEM_LIST::Draw( EDA_RECT* aClipBox, wxDC* aDC ) } // The selected items are drawn after (usually 0 or 1) - int markerSize = WORKSHEET_DATAITEM::GetMarkerSizeUi(); + int markerSize = WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ); for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() ) { @@ -210,12 +210,12 @@ bool WS_DRAW_ITEM_TEXT::HitTest( const EDA_RECT& aRect ) const } -bool WS_DRAW_ITEM_TEXT::HitTestStartPoint( const wxPoint& aPosition) +bool WS_DRAW_ITEM_TEXT::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) { wxPoint pos = GetTextPos(); - if( std::abs( pos.x - aPosition.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 && - std::abs( pos.y - aPosition.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 ) + if( std::abs( pos.x - aPosition.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 && + std::abs( pos.y - aPosition.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 ) return true; return false; @@ -276,12 +276,12 @@ bool WS_DRAW_ITEM_POLYGON::HitTest( const EDA_RECT& aRect ) const } -bool WS_DRAW_ITEM_POLYGON::HitTestStartPoint( const wxPoint& aPosition) +bool WS_DRAW_ITEM_POLYGON::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) { wxPoint pos = GetPosition(); - if( std::abs( pos.x - aPosition.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 && - std::abs( pos.y - aPosition.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 ) + if( std::abs( pos.x - aPosition.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 && + std::abs( pos.y - aPosition.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 ) return true; return false; @@ -368,25 +368,25 @@ bool WS_DRAW_ITEM_RECT::HitTest( const EDA_RECT& aRect ) const } -bool WS_DRAW_ITEM_RECT::HitTestStartPoint( const wxPoint& aPosition) +bool WS_DRAW_ITEM_RECT::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) { wxPoint dist = GetStart() - aPosition; - if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 && - std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 ) + if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 && + std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 ) return true; return false; } -bool WS_DRAW_ITEM_RECT::HitTestEndPoint( const wxPoint& aPosition) +bool WS_DRAW_ITEM_RECT::HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) { wxPoint pos = GetEnd(); int dist = (int) hypot( pos.x - aPosition.x, pos.y - aPosition.y ); - if( dist <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 ) + if( dist <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 ) return true; return false; @@ -416,45 +416,45 @@ bool WS_DRAW_ITEM_LINE::HitTest( const EDA_RECT& aRect ) const } -bool WS_DRAW_ITEM_LINE::HitTestStartPoint( const wxPoint& aPosition) +bool WS_DRAW_ITEM_LINE::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) { wxPoint dist = GetStart() - aPosition; - if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 && - std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 ) + if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 && + std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 ) return true; return false; } -bool WS_DRAW_ITEM_LINE::HitTestEndPoint( const wxPoint& aPosition) +bool WS_DRAW_ITEM_LINE::HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) { wxPoint dist = GetEnd() - aPosition; - if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 && - std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 ) + if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 && + std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 ) return true; return false; } -void WS_DRAW_ITEM_LIST::Locate( std::vector & aList, - const wxPoint& aPosition) +void WS_DRAW_ITEM_LIST::Locate( wxDC* aDC, std::vector & aList, + const wxPoint& aPosition ) { for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() ) { item->m_Flags &= ~(LOCATE_STARTPOINT|LOCATE_ENDPOINT); bool found = false; - if( item->HitTestStartPoint ( aPosition ) ) + if( item->HitTestStartPoint ( aDC, aPosition ) ) { item->m_Flags |= LOCATE_STARTPOINT; found = true; } - if( item->HitTestEndPoint ( aPosition ) ) + if( item->HitTestEndPoint ( aDC, aPosition ) ) { item->m_Flags |= LOCATE_ENDPOINT; found = true; @@ -511,12 +511,12 @@ bool WS_DRAW_ITEM_BITMAP::HitTest( const EDA_RECT& aRect ) const /** * return true if the point aPosition is on the reference point of this item. */ -bool WS_DRAW_ITEM_BITMAP::HitTestStartPoint( const wxPoint& aPosition) +bool WS_DRAW_ITEM_BITMAP::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) { wxPoint dist = m_pos - aPosition; - if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 && - std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 ) + if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 && + std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 ) return true; return false; diff --git a/include/worksheet_dataitem.h b/include/worksheet_dataitem.h index b4c21bbad6..965c4f74b8 100644 --- a/include/worksheet_dataitem.h +++ b/include/worksheet_dataitem.h @@ -205,9 +205,15 @@ public: return KiROUND( m_DefaultLineWidth * m_WSunits2Iu ); } - static int GetMarkerSizeUi() + static int GetMarkerSizeUi( wxDC* aDC ) { - return KiROUND( 0.5 * m_WSunits2Iu ); + double x, y; + double scale; + + aDC->GetUserScale( &x, &y ); + scale = (x + y ) / 2; // should be equal, but if not best we can do is average + + return KiROUND( 0.01 * m_WSunits2Iu / scale ); } /** diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h index c30f58fc88..a9418b4667 100644 --- a/include/worksheet_shape_builder.h +++ b/include/worksheet_shape_builder.h @@ -119,7 +119,7 @@ public: * (texts or polygons) * the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 */ - virtual bool HitTestStartPoint( const wxPoint& aPosition) = 0; + virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) = 0; /** * return true if the point aPosition is near the ending point of this item @@ -127,7 +127,7 @@ public: * 2 points * the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 */ - virtual bool HitTestEndPoint( const wxPoint& aPosition) + virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition) { return false; } @@ -176,14 +176,14 @@ public: /** * return true if the point aPosition is on the starting point of this item. */ - virtual bool HitTestStartPoint( const wxPoint& aPosition) override; + virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; /** * return true if the point aPosition is on the ending point of this item * This is avirtual function which should be overriden for items defien by * 2 points */ - virtual bool HitTestEndPoint( const wxPoint& aPosition) override; + virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) override; }; // This class draws a polygon @@ -233,7 +233,7 @@ public: /** * return true if the point aPosition is on the starting point of this item. */ - virtual bool HitTestStartPoint( const wxPoint& aPosition) override; + virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; }; // This class draws a not filled rectangle with thick segment @@ -268,14 +268,14 @@ public: /** * return true if the point aPosition is on the starting point of this item. */ - virtual bool HitTestStartPoint( const wxPoint& aPosition) override; + virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; /** * return true if the point aPosition is on the ending point of this item * This is avirtual function which should be overriden for items defien by * 2 points */ - virtual bool HitTestEndPoint( const wxPoint& aPosition) override; + virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) override; }; // This class draws a graphic text. @@ -317,7 +317,7 @@ public: /** * return true if the point aPosition is on the starting point of this item. */ - virtual bool HitTestStartPoint( const wxPoint& aPosition) override; + virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; }; // This class draws a bitmap. @@ -359,7 +359,7 @@ public: /** * return true if the point aPosition is on the reference point of this item. */ - virtual bool HitTestStartPoint( const wxPoint& aPosition) override; + virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override; const wxPoint GetPosition() const { return m_pos; } }; @@ -592,7 +592,7 @@ public: * @param aList = the list of items found * @param aPosition the position (in user units) to locate items */ - void Locate(std::vector & aList, const wxPoint& aPosition); + void Locate(wxDC* aDC, std::vector & aList, const wxPoint& aPosition); }; diff --git a/pagelayout_editor/hotkeys.cpp b/pagelayout_editor/hotkeys.cpp index f2cbb0f114..ba31a1681f 100644 --- a/pagelayout_editor/hotkeys.cpp +++ b/pagelayout_editor/hotkeys.cpp @@ -267,7 +267,7 @@ bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, if( busy ) break; - if( (item = Locate( aPosition )) == NULL ) + if( (item = Locate( aDC, aPosition ) ) == NULL ) break; // Only rect and lines have a end point. diff --git a/pagelayout_editor/onleftclick.cpp b/pagelayout_editor/onleftclick.cpp index 6447ceff2f..3cdcc7d570 100644 --- a/pagelayout_editor/onleftclick.cpp +++ b/pagelayout_editor/onleftclick.cpp @@ -55,7 +55,7 @@ void PL_EDITOR_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } item = m_treePagelayout->GetPageLayoutSelectedItem(); - WORKSHEET_DATAITEM* newitem = Locate( aPosition ); + WORKSHEET_DATAITEM* newitem = Locate( aDC, aPosition ); if( newitem == NULL ) return; diff --git a/pagelayout_editor/onrightclick.cpp b/pagelayout_editor/onrightclick.cpp index 2dd420096d..b89a4d15d6 100644 --- a/pagelayout_editor/onrightclick.cpp +++ b/pagelayout_editor/onrightclick.cpp @@ -38,6 +38,7 @@ #include #include #include +#include // Helper function to add menuitems relative to items creation void AddNewItemsCommand( wxMenu* aMainMenu ) @@ -83,8 +84,9 @@ bool PL_EDITOR_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* aPopMenu ) if( ! busy ) // No item currently edited { + INSTALL_UNBUFFERED_DC( dc, m_canvas ); WORKSHEET_DATAITEM* old_item = m_treePagelayout->GetPageLayoutSelectedItem(); - WORKSHEET_DATAITEM* item = Locate( aPosition ); + WORKSHEET_DATAITEM* item = Locate( &dc, aPosition ); if( item && old_item != item ) { diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 09a59b1749..9556a8c5d8 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -600,7 +600,7 @@ WORKSHEET_DATAITEM * PL_EDITOR_FRAME::GetSelectedItem() } -WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( const wxPoint& aPosition ) +WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( wxDC* aDC, const wxPoint& aPosition ) { const PAGE_INFO& pageInfo = GetPageSettings(); TITLE_BLOCK t_block = GetTitleBlock(); @@ -625,7 +625,7 @@ WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( const wxPoint& aPosition ) // We do not use here the COLLECTOR classes in use in pcbnew and eeschema // because the locate requirements are very basic. std::vector list; - drawList.Locate( list, aPosition ); + drawList.Locate( aDC, list, aPosition ); if( list.size() == 0 ) return NULL; diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index a3ac232023..f8bdce8e96 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -358,7 +358,7 @@ public: * @return the page layout item found at position aPosition * @param aPosition = the position (in user units) of the reference point */ - WORKSHEET_DATAITEM *Locate( const wxPoint& aPosition ); + WORKSHEET_DATAITEM *Locate( wxDC* aDC, const wxPoint& aPosition ); /** * Initialize a move item command