Skip to content

Commit

Permalink
Constant-size page layout object handles w/respect to zoom.
Browse files Browse the repository at this point in the history
  • Loading branch information
jey5nd6 committed Aug 21, 2018
1 parent 86a801a commit a6d10d6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 43 deletions.
50 changes: 25 additions & 25 deletions common/page_layout/page_layout_graphic_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 <WS_DRAW_ITEM_BASE*>& aList,
const wxPoint& aPosition)
void WS_DRAW_ITEM_LIST::Locate( wxDC* aDC, std::vector <WS_DRAW_ITEM_BASE*>& 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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions include/worksheet_dataitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,15 @@ class WORKSHEET_DATAITEM
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 );
}

/**
Expand Down
20 changes: 10 additions & 10 deletions include/worksheet_shape_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ class WS_DRAW_ITEM_BASE // This basic class, not directly usable.
* (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
* This is avirtual function which should be overriden for items defien by
* 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;
}
Expand Down Expand Up @@ -176,14 +176,14 @@ class WS_DRAW_ITEM_LINE : public WS_DRAW_ITEM_BASE
/**
* 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
Expand Down Expand Up @@ -233,7 +233,7 @@ class WS_DRAW_ITEM_POLYGON : public WS_DRAW_ITEM_BASE
/**
* 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
Expand Down Expand Up @@ -268,14 +268,14 @@ class WS_DRAW_ITEM_RECT : public WS_DRAW_ITEM_LINE
/**
* 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.
Expand Down Expand Up @@ -317,7 +317,7 @@ class WS_DRAW_ITEM_TEXT : public WS_DRAW_ITEM_BASE, public EDA_TEXT
/**
* 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.
Expand Down Expand Up @@ -359,7 +359,7 @@ class WS_DRAW_ITEM_BITMAP : public WS_DRAW_ITEM_BASE
/**
* 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; }
};
Expand Down Expand Up @@ -592,7 +592,7 @@ class WS_DRAW_ITEM_LIST
* @param aList = the list of items found
* @param aPosition the position (in user units) to locate items
*/
void Locate(std::vector <WS_DRAW_ITEM_BASE*>& aList, const wxPoint& aPosition);
void Locate(wxDC* aDC, std::vector <WS_DRAW_ITEM_BASE*>& aList, const wxPoint& aPosition);
};


Expand Down
2 changes: 1 addition & 1 deletion pagelayout_editor/hotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pagelayout_editor/onleftclick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion pagelayout_editor/onrightclick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <worksheet_shape_builder.h>
#include <worksheet_dataitem.h>
#include <hotkeys.h>
#include <kicad_device_context.h>

// Helper function to add menuitems relative to items creation
void AddNewItemsCommand( wxMenu* aMainMenu )
Expand Down Expand Up @@ -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 )
{
Expand Down
4 changes: 2 additions & 2 deletions pagelayout_editor/pl_editor_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 <WS_DRAW_ITEM_BASE*> list;
drawList.Locate( list, aPosition );
drawList.Locate( aDC, list, aPosition );

if( list.size() == 0 )
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion pagelayout_editor/pl_editor_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class PL_EDITOR_FRAME : public EDA_DRAW_FRAME
* @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
Expand Down

0 comments on commit a6d10d6

Please sign in to comment.