2009-11-23 15:16:50 +00:00
|
|
|
/*****************/
|
|
|
|
/* drawpanel.cpp */
|
|
|
|
/*****************/
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "macros.h"
|
|
|
|
#include "id.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "class_base_screen.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
|
2010-01-14 08:55:45 +00:00
|
|
|
#include <wx/wupdlock.h>
|
2009-12-20 19:48:58 +00:00
|
|
|
#include "kicad_device_context.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-10-06 16:16:48 +00:00
|
|
|
#define CURSOR_SIZE 12 // Cursor size in pixels
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
#define CLIP_BOX_PADDING 12
|
2008-08-26 09:06:26 +00:00
|
|
|
|
2009-12-19 16:10:25 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
/* Definitions for enabling and disabling debugging features in drawpanel.cpp.
|
|
|
|
* Please don't forget to turn these off before making any SvN commits.
|
|
|
|
*/
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
#define DEBUG_SHOW_CLIP_RECT 0 // Set to 1 to draw clipping rectangle.
|
|
|
|
#define DEBUG_DUMP_CLIP_COORDS 0 // Set to 1 to dump clipping rectangle coordinates.
|
|
|
|
#define DEBUG_DUMP_SCROLL_SETTINGS 0 // Set to 1 to dump scroll settings.
|
2009-12-19 16:10:25 +00:00
|
|
|
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Used to inhibit a response to a mouse left button release, after a
|
|
|
|
* double click (when releasing the left button at the end of the second
|
|
|
|
* click. Used in eeschema to inhibit a mouse left release command when
|
|
|
|
* switching between hierarchical sheets on a double click.
|
2008-08-26 09:06:26 +00:00
|
|
|
*/
|
|
|
|
static bool s_IgnoreNextLeftButtonRelease = false;
|
|
|
|
|
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
// Events used by WinEDA_DrawPanel
|
2008-04-17 16:25:29 +00:00
|
|
|
BEGIN_EVENT_TABLE( WinEDA_DrawPanel, wxScrolledWindow )
|
2010-02-08 18:15:42 +00:00
|
|
|
EVT_LEAVE_WINDOW( WinEDA_DrawPanel::OnMouseLeaving )
|
|
|
|
EVT_MOUSEWHEEL( WinEDA_DrawPanel::OnMouseWheel )
|
|
|
|
EVT_MOUSE_EVENTS( WinEDA_DrawPanel::OnMouseEvent )
|
|
|
|
EVT_CHAR( WinEDA_DrawPanel::OnKeyEvent )
|
|
|
|
EVT_CHAR_HOOK( WinEDA_DrawPanel::OnKeyEvent )
|
|
|
|
EVT_PAINT( WinEDA_DrawPanel::OnPaint )
|
|
|
|
EVT_SIZE( WinEDA_DrawPanel::OnSize )
|
|
|
|
EVT_SCROLLWIN( WinEDA_DrawPanel::OnScroll )
|
|
|
|
EVT_ACTIVATE( WinEDA_DrawPanel::OnActivate )
|
|
|
|
EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, WinEDA_DrawPanel::OnPan )
|
2007-05-06 16:03:28 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/***********************************************************************/
|
|
|
|
/* WinEDA_DrawPanel base functions (WinEDA_DrawPanel is the main panel)*/
|
|
|
|
/***********************************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
WinEDA_DrawPanel::WinEDA_DrawPanel( WinEDA_DrawFrame* parent, int id,
|
|
|
|
const wxPoint& pos, const wxSize& size ) :
|
2008-04-17 16:25:29 +00:00
|
|
|
wxScrolledWindow( parent, id, pos, size,
|
2008-08-26 09:06:26 +00:00
|
|
|
wxBORDER | wxNO_FULL_REPAINT_ON_RESIZE )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-01-17 14:20:29 +00:00
|
|
|
m_Parent = parent;
|
2009-12-20 19:48:58 +00:00
|
|
|
wxASSERT( m_Parent );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
|
|
|
m_scrollIncrementX = MIN( size.x / 8, 10 );
|
|
|
|
m_scrollIncrementY = MIN( size.y / 8, 10 );
|
2007-08-22 05:11:01 +00:00
|
|
|
SetBackgroundColour( wxColour( ColorRefs[g_DrawBgColor].m_Red,
|
2008-08-26 09:06:26 +00:00
|
|
|
ColorRefs[g_DrawBgColor].m_Green,
|
|
|
|
ColorRefs[g_DrawBgColor].m_Blue ) );
|
2010-01-14 20:20:59 +00:00
|
|
|
#if defined KICAD_USE_BUFFERED_DC || defined KICAD_USE_BUFFERED_PAINTDC
|
2009-12-29 10:35:11 +00:00
|
|
|
SetBackgroundStyle( wxBG_STYLE_CUSTOM );
|
2010-01-14 20:20:59 +00:00
|
|
|
#endif
|
2007-08-22 05:11:01 +00:00
|
|
|
EnableScrolling( TRUE, TRUE );
|
|
|
|
m_ClipBox.SetSize( size );
|
|
|
|
m_ClipBox.SetX( 0 );
|
|
|
|
m_ClipBox.SetY( 0 );
|
|
|
|
m_CanStartBlock = -1; // Command block can start if >= 0
|
2009-12-29 10:35:11 +00:00
|
|
|
m_AbortEnable = m_AbortRequest = false;
|
2007-08-22 05:11:01 +00:00
|
|
|
m_AutoPAN_Enable = TRUE;
|
2007-09-15 04:25:54 +00:00
|
|
|
m_IgnoreMouseEvents = 0;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
ManageCurseur = NULL;
|
|
|
|
ForceCloseManageCurseur = NULL;
|
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
if( wxGetApp().m_EDA_Config )
|
2009-05-21 17:42:42 +00:00
|
|
|
wxGetApp().m_EDA_Config->Read( wxT( "AutoPAN" ), &m_AutoPAN_Enable,
|
|
|
|
true );
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2009-12-29 10:35:11 +00:00
|
|
|
m_AutoPAN_Request = false;
|
|
|
|
m_Block_Enable = false;
|
2007-08-22 05:11:01 +00:00
|
|
|
m_PanelDefaultCursor = m_PanelCursor = wxCURSOR_ARROW;
|
2010-01-17 14:20:29 +00:00
|
|
|
m_CursorLevel = 0;
|
2008-11-02 19:52:57 +00:00
|
|
|
m_PrintIsMirrored = false;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2009-04-08 18:06:22 +00:00
|
|
|
WinEDA_DrawPanel::~WinEDA_DrawPanel()
|
|
|
|
{
|
|
|
|
wxGetApp().m_EDA_Config->Write( wxT( "AutoPAN" ), m_AutoPAN_Enable );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
BASE_SCREEN* WinEDA_DrawPanel::GetScreen()
|
|
|
|
{
|
2008-08-26 09:06:26 +00:00
|
|
|
WinEDA_DrawFrame* parentFrame = m_Parent;
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
return parentFrame->GetBaseScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/*
|
2007-10-06 16:16:48 +00:00
|
|
|
* Draw the schematic cursor which is usually on grid
|
2009-11-23 15:16:50 +00:00
|
|
|
*/
|
2010-01-22 18:13:43 +00:00
|
|
|
void WinEDA_DrawPanel::DrawCursor( wxDC* aDC, int aColor )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-01-22 18:13:43 +00:00
|
|
|
if( m_CursorLevel != 0 || aDC == NULL )
|
2007-08-22 05:11:01 +00:00
|
|
|
return;
|
|
|
|
|
2007-10-06 16:16:48 +00:00
|
|
|
wxPoint Cursor = GetScreen()->m_Curseur;
|
|
|
|
|
2010-01-22 18:13:43 +00:00
|
|
|
GRSetDrawMode( aDC, GR_XOR );
|
2010-02-10 21:39:32 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
if( m_Parent->m_CursorShape == 1 ) /* Draws a crosshair. */
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
2010-02-08 18:15:42 +00:00
|
|
|
#ifdef USE_WX_ZOOM
|
2010-02-10 21:39:32 +00:00
|
|
|
wxSize clientSize = GetClientSize();
|
|
|
|
wxPoint lineStart = wxPoint( Cursor.x, aDC->DeviceToLogicalY( 0 ) );
|
|
|
|
wxPoint lineEnd = wxPoint( Cursor.x, aDC->DeviceToLogicalY( clientSize.y ) );
|
|
|
|
GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor ); // Y azis
|
|
|
|
lineStart = wxPoint( aDC->DeviceToLogicalX( 0 ), Cursor.y );
|
|
|
|
lineEnd = wxPoint( aDC->DeviceToLogicalX( clientSize.x ), Cursor.y );
|
|
|
|
GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor ); // X azis
|
2010-02-08 18:15:42 +00:00
|
|
|
#else
|
2009-01-29 14:26:20 +00:00
|
|
|
int dx = GetScreen()->Unscale( m_ClipBox.GetWidth() );
|
|
|
|
int dy = GetScreen()->Unscale( m_ClipBox.GetHeight() );
|
2010-01-22 18:13:43 +00:00
|
|
|
GRLine( &m_ClipBox, aDC, Cursor.x - dx, Cursor.y,
|
|
|
|
Cursor.x + dx, Cursor.y, 0, aColor ); // Y axis
|
|
|
|
GRLine( &m_ClipBox, aDC, Cursor.x, Cursor.y - dx,
|
|
|
|
Cursor.x, Cursor.y + dy, 0, aColor ); // X axis
|
2010-02-10 21:39:32 +00:00
|
|
|
#endif
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-08 18:15:42 +00:00
|
|
|
#ifdef USE_WX_ZOOM
|
|
|
|
int len = aDC->DeviceToLogicalXRel( CURSOR_SIZE );
|
|
|
|
#else
|
2009-01-29 14:26:20 +00:00
|
|
|
int len = GetScreen()->Unscale( CURSOR_SIZE );
|
2010-02-08 18:15:42 +00:00
|
|
|
#endif
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2010-01-22 18:13:43 +00:00
|
|
|
GRLine( &m_ClipBox, aDC, Cursor.x - len, Cursor.y,
|
|
|
|
Cursor.x + len, Cursor.y, 0, aColor );
|
|
|
|
GRLine( &m_ClipBox, aDC, Cursor.x, Cursor.y - len,
|
|
|
|
Cursor.x, Cursor.y + len, 0, aColor );
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*
|
2009-11-23 15:16:50 +00:00
|
|
|
* Remove the grid cursor from the display in preparation for other drawing
|
|
|
|
* operations
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawPanel::CursorOff( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-01-22 18:13:43 +00:00
|
|
|
DrawCursor( DC );
|
2007-08-22 05:11:01 +00:00
|
|
|
--m_CursorLevel;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*
|
2007-08-22 05:11:01 +00:00
|
|
|
* Display the grid cursor
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawPanel::CursorOn( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
++m_CursorLevel;
|
2010-01-22 18:13:43 +00:00
|
|
|
DrawCursor( DC );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
if( m_CursorLevel > 0 ) // Shouldn't happen, but just in case ..
|
|
|
|
m_CursorLevel = 0;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
int WinEDA_DrawPanel::GetZoom()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
return GetScreen()->GetZoom();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
void WinEDA_DrawPanel::SetZoom( int zoom )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
GetScreen()->SetZoom( zoom );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2009-02-07 08:33:25 +00:00
|
|
|
wxRealPoint WinEDA_DrawPanel::GetGrid()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-10-14 19:43:31 +00:00
|
|
|
return GetScreen()->GetGridSize();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
/**
|
|
|
|
* Convert a coordinate position in device (screen) units to logical (drawing) units.
|
|
|
|
*
|
|
|
|
* @param aPosition = position in device (screen) units.
|
|
|
|
* @return position in logical (drawing) units.
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2010-02-08 18:15:42 +00:00
|
|
|
wxPoint WinEDA_DrawPanel::CursorRealPosition( const wxPoint& aPosition )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-02-22 16:45:35 +00:00
|
|
|
double scalar = GetScreen()->GetScalingFactor();
|
|
|
|
wxPoint pos;
|
|
|
|
pos.x = wxRound( (double) aPosition.x / scalar );
|
|
|
|
pos.y = wxRound( (double) aPosition.y / scalar );
|
|
|
|
pos += GetScreen()->m_DrawOrg;
|
|
|
|
return pos;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/** Function IsPointOnDisplay
|
2007-12-09 09:00:15 +00:00
|
|
|
* @param ref_pos is the position to test in pixels, relative to the panel.
|
|
|
|
* @return TRUE if ref_pos is a point currently visible on screen
|
2009-12-29 10:35:11 +00:00
|
|
|
* false if ref_pos is out of screen
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
bool WinEDA_DrawPanel::IsPointOnDisplay( wxPoint ref_pos )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
wxPoint pos;
|
|
|
|
EDA_Rect display_rect;
|
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
INSTALL_DC( dc, this ); // Refresh the boundary box.
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
display_rect = m_ClipBox;
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// Slightly decreased the size of the useful screen area to avoid drawing
|
|
|
|
// limits.
|
2007-08-22 05:11:01 +00:00
|
|
|
#define PIXEL_MARGIN 8
|
2009-12-29 10:35:11 +00:00
|
|
|
display_rect.Inflate( -PIXEL_MARGIN );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
#ifndef USE_WX_ZOOM
|
2009-11-23 15:16:50 +00:00
|
|
|
// Convert physical coordinates.
|
2009-01-17 20:31:19 +00:00
|
|
|
pos = CalcUnscrolledPosition( display_rect.GetPosition() );
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
GetScreen()->Unscale( pos );
|
2009-01-17 20:31:19 +00:00
|
|
|
pos += GetScreen()->m_DrawOrg;
|
2009-01-29 14:26:20 +00:00
|
|
|
display_rect.m_Pos = pos;
|
|
|
|
GetScreen()->Unscale( display_rect.m_Size );
|
2010-02-08 18:15:42 +00:00
|
|
|
#endif
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
return display_rect.Inside( ref_pos );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-10 15:00:22 +00:00
|
|
|
void WinEDA_DrawPanel::PostDirtyRect( EDA_Rect aRect )
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
// D( printf( "1) PostDirtyRect( x=%d, y=%d, width=%d, height=%d)\n", aRect.m_Pos.x, aRect.m_Pos.y, aRect.m_Size.x, aRect.m_Size.y ); )
|
2008-05-17 19:08:23 +00:00
|
|
|
|
2008-03-10 15:00:22 +00:00
|
|
|
// Convert the rect coordinates and size to pixels (make a draw clip box):
|
|
|
|
ConvertPcbUnitsToPixelsUnits( &aRect );
|
|
|
|
|
2008-03-10 15:51:44 +00:00
|
|
|
// Ensure the rectangle is large enough after truncations.
|
|
|
|
// The pcb units have finer granularity than the pixels, so it can happen
|
|
|
|
// that the rectangle is not large enough for the erase portion.
|
2008-03-11 01:19:08 +00:00
|
|
|
|
2009-06-25 20:45:27 +00:00
|
|
|
aRect.m_Size.x += 4; // += 1 is not enough!
|
|
|
|
aRect.m_Size.y += 4;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
// D( printf( "2) PostDirtyRect( x=%d, y=%d, width=%d, height=%d)\n", aRect.m_Pos.x, aRect.m_Pos.y, aRect.m_Size.x, aRect.m_Size.y ); )
|
2008-05-17 19:08:23 +00:00
|
|
|
|
2008-03-10 15:00:22 +00:00
|
|
|
// pass wxRect() via EDA_Rect::operator wxRect() overload
|
|
|
|
RefreshRect( aRect, TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
/**
|
|
|
|
* Scale and offset a rectangle in drawing units to device units.
|
|
|
|
*
|
|
|
|
* This is the equivalent of wxDC::LogicalToDevice.
|
|
|
|
*
|
|
|
|
* @param aRect - Rectangle to scale.
|
|
|
|
*/
|
2008-03-10 13:33:12 +00:00
|
|
|
void WinEDA_DrawPanel::ConvertPcbUnitsToPixelsUnits( EDA_Rect* aRect )
|
2008-03-10 08:14:20 +00:00
|
|
|
{
|
|
|
|
// Calculate the draw area origin in internal units:
|
2008-03-10 13:33:12 +00:00
|
|
|
wxPoint pos = aRect->GetPosition();
|
|
|
|
|
|
|
|
ConvertPcbUnitsToPixelsUnits( &pos );
|
|
|
|
aRect->SetOrigin( pos ); // rect origin in pixel units
|
2010-02-08 18:15:42 +00:00
|
|
|
|
|
|
|
double scale = GetScreen()->GetScalingFactor();
|
|
|
|
aRect->m_Size.x = wxRound( (double) aRect->m_Size.x * scale );
|
|
|
|
aRect->m_Size.y = wxRound( (double) aRect->m_Size.y * scale );
|
2008-03-10 08:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-10 13:33:12 +00:00
|
|
|
void WinEDA_DrawPanel::ConvertPcbUnitsToPixelsUnits( wxPoint* aPosition )
|
2008-03-10 08:14:20 +00:00
|
|
|
{
|
|
|
|
// Calculate the draw area origin in internal units:
|
|
|
|
wxPoint drwOrig;
|
|
|
|
int x_axis_scale, y_axis_scale;
|
|
|
|
|
2008-03-10 13:33:12 +00:00
|
|
|
// Origin in scroll units;
|
|
|
|
GetViewStart( &drwOrig.x, &drwOrig.y );
|
2008-03-10 08:14:20 +00:00
|
|
|
GetScrollPixelsPerUnit( &x_axis_scale, &y_axis_scale );
|
|
|
|
|
2008-03-10 13:33:12 +00:00
|
|
|
// Origin in pixels units
|
|
|
|
drwOrig.x *= x_axis_scale;
|
|
|
|
drwOrig.y *= y_axis_scale;
|
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
double x, y;
|
|
|
|
double scalar = GetScreen()->GetScalingFactor();
|
|
|
|
x = (double) aPosition->x - ( ( (double) drwOrig.x / scalar )
|
|
|
|
+ (double) GetScreen()->m_DrawOrg.x );
|
|
|
|
y = (double) aPosition->y - ( ( (double) drwOrig.y / scalar )
|
|
|
|
+ (double) GetScreen()->m_DrawOrg.y );
|
|
|
|
aPosition->x = wxRound( x * scalar );
|
|
|
|
aPosition->y = wxRound( y * scalar );
|
2008-03-10 08:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-31 10:05:16 +00:00
|
|
|
/** Function CursorScreenPosition
|
2009-04-05 20:49:15 +00:00
|
|
|
* @return the cursor current position in pixels in the screen draw area
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2009-04-29 17:09:00 +00:00
|
|
|
wxPoint WinEDA_DrawPanel::CursorScreenPosition()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-02-08 18:15:42 +00:00
|
|
|
wxPoint pos = GetScreen()->m_Curseur - GetScreen()->m_DrawOrg;
|
2010-02-22 16:45:35 +00:00
|
|
|
double scalar = GetScreen()->GetScalingFactor();
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
pos.x = wxRound( (double) pos.x * scalar );
|
|
|
|
pos.y = wxRound( (double) pos.y * scalar );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
|
|
|
return pos;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
/** Function GetScreenCenterRealPosition()
|
2009-11-23 15:16:50 +00:00
|
|
|
* @return position (in internal units) of the current area center showed
|
|
|
|
* on screen
|
2007-12-09 09:00:15 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition( void )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-02-22 16:45:35 +00:00
|
|
|
int x, y, ppuX, ppuY;
|
|
|
|
wxPoint pos;
|
|
|
|
double scalar = GetScreen()->GetScalingFactor();
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
GetViewStart( &x, &y );
|
|
|
|
GetScrollPixelsPerUnit( &ppuX, &ppuY );
|
|
|
|
x *= ppuX;
|
|
|
|
y *= ppuY;
|
|
|
|
pos.x = wxRound( ( (double) GetClientSize().x / 2.0 + (double) x ) / scalar );
|
|
|
|
pos.y = wxRound( ( (double) GetClientSize().y / 2.0 + (double) y ) / scalar );
|
|
|
|
pos += GetScreen()->m_DrawOrg;
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
return pos;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 16:16:48 +00:00
|
|
|
/* Move the mouse cursor to the current schematic cursor
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawPanel::MouseToCursorSchema()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
wxPoint Mouse = CursorScreenPosition();
|
|
|
|
|
|
|
|
MouseTo( Mouse );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2007-10-06 16:16:48 +00:00
|
|
|
/** Move the mouse cursor to the position "Mouse"
|
2009-02-26 20:06:51 +00:00
|
|
|
* @param Mouse = mouse cursor position, in pixels units
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawPanel::MouseTo( const wxPoint& Mouse )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-02-05 20:53:08 +00:00
|
|
|
int x, y, xPpu, yPpu;
|
|
|
|
wxPoint screenPos, drawingPos;
|
|
|
|
wxRect clientRect( wxPoint( 0, 0 ), GetClientSize() );
|
|
|
|
|
|
|
|
CalcScrolledPosition( Mouse.x, Mouse.y, &screenPos.x, &screenPos.y );
|
|
|
|
|
|
|
|
/* Scroll if the requested mouse position cursor is outside the drawing
|
|
|
|
* area. */
|
|
|
|
if( !clientRect.Contains( screenPos ) )
|
|
|
|
{
|
|
|
|
GetViewStart( &x, &y );
|
|
|
|
GetScrollPixelsPerUnit( &xPpu, &yPpu );
|
|
|
|
CalcUnscrolledPosition( screenPos.x, screenPos.y,
|
|
|
|
&drawingPos.x, &drawingPos.y );
|
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
wxLogDebug( wxT( "MouseTo() initial screen position(%d, %d) " ) \
|
|
|
|
wxT( "rectangle(%d, %d, %d, %d) view(%d, %d)" ),
|
2009-02-05 20:53:08 +00:00
|
|
|
screenPos.x, screenPos.y, clientRect.x, clientRect.y,
|
|
|
|
clientRect.width, clientRect.height, x, y );
|
|
|
|
|
|
|
|
if( screenPos.y < clientRect.GetTop() )
|
2010-02-08 18:15:42 +00:00
|
|
|
y -= m_scrollIncrementY * yPpu;
|
2009-02-05 20:53:08 +00:00
|
|
|
else if( screenPos.y > clientRect.GetBottom() )
|
2010-02-08 18:15:42 +00:00
|
|
|
y += m_scrollIncrementY * yPpu;
|
2009-02-05 20:53:08 +00:00
|
|
|
else if( clientRect.GetRight() < screenPos.x )
|
2010-02-08 18:15:42 +00:00
|
|
|
x += m_scrollIncrementX * xPpu;
|
2009-02-05 20:53:08 +00:00
|
|
|
else
|
2010-02-08 18:15:42 +00:00
|
|
|
x -= m_scrollIncrementX * xPpu;
|
2009-02-05 20:53:08 +00:00
|
|
|
|
|
|
|
Scroll( x, y );
|
|
|
|
CalcScrolledPosition( drawingPos.x, drawingPos.y,
|
|
|
|
&screenPos.x, &screenPos.y );
|
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
wxLogDebug( wxT( "MouseTo() scrolled screen position(%d, %d) " ) \
|
|
|
|
wxT( "view(%d, %d)" ), screenPos.x, screenPos.y, x, y );
|
2009-02-05 20:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WarpPointer( screenPos.x, screenPos.y );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
/**
|
|
|
|
* Called on window activation.
|
|
|
|
* init the member m_CanStartBlock to avoid a block start command
|
2009-11-23 15:16:50 +00:00
|
|
|
* on activation (because a left mouse button can be pressed and no block
|
|
|
|
* command wanted.
|
|
|
|
* This happens when enter on a hierarchy sheet on double click
|
2007-12-09 09:00:15 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawPanel::OnActivate( wxActivateEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-06 16:16:48 +00:00
|
|
|
m_CanStartBlock = -1; // Block Command can't start
|
2007-08-22 05:11:01 +00:00
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
void WinEDA_DrawPanel::OnScroll( wxScrollWinEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
int id = event.GetEventType();
|
2010-02-22 16:45:35 +00:00
|
|
|
int dir;
|
2007-08-22 05:11:01 +00:00
|
|
|
int x, y;
|
2010-02-22 16:45:35 +00:00
|
|
|
int ppux, ppuy;
|
|
|
|
int unitsX, unitsY;
|
|
|
|
int maxX, maxY;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
GetViewStart( &x, &y );
|
2010-02-22 16:45:35 +00:00
|
|
|
GetScrollPixelsPerUnit( &ppux, &ppuy );
|
|
|
|
GetVirtualSize( &unitsX, &unitsY );
|
|
|
|
maxX = unitsX;
|
|
|
|
maxY = unitsY;
|
|
|
|
|
|
|
|
unitsX /= ppux;
|
|
|
|
unitsY /= ppuy;
|
|
|
|
|
2007-10-06 16:16:48 +00:00
|
|
|
dir = event.GetOrientation(); // wxHORIZONTAL or wxVERTICAL
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
if( id == wxEVT_SCROLLWIN_LINEUP )
|
2010-02-22 16:45:35 +00:00
|
|
|
{
|
|
|
|
if( dir == wxHORIZONTAL )
|
|
|
|
{
|
|
|
|
x -= m_scrollIncrementX;
|
|
|
|
if( x < 0 )
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y -= m_scrollIncrementY;
|
|
|
|
if( y < 0 )
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
else if( id == wxEVT_SCROLLWIN_LINEDOWN )
|
2010-02-22 16:45:35 +00:00
|
|
|
{
|
|
|
|
if( dir == wxHORIZONTAL )
|
|
|
|
{
|
|
|
|
x += m_scrollIncrementX;
|
|
|
|
if( x > maxX )
|
|
|
|
x = maxX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y += m_scrollIncrementY;
|
|
|
|
if( y > maxY )
|
|
|
|
y = maxY;
|
|
|
|
}
|
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
else if( id == wxEVT_SCROLLWIN_THUMBTRACK )
|
|
|
|
{
|
|
|
|
if( dir == wxHORIZONTAL )
|
2010-02-22 16:45:35 +00:00
|
|
|
x = event.GetPosition();
|
2007-08-22 05:11:01 +00:00
|
|
|
else
|
2010-02-22 16:45:35 +00:00
|
|
|
y = event.GetPosition();
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
#if DEBUG_DUMP_SCROLL_SETTINGS
|
|
|
|
wxLogDebug( wxT( "Setting scroll bars ppuX=%d, ppuY=%d, unitsX=%d, unitsY=%d," \
|
|
|
|
"posX=%d, posY=%d" ), ppux, ppuy, unitsX, unitsY, x, y );
|
|
|
|
#endif
|
2010-02-10 21:39:32 +00:00
|
|
|
|
2010-02-23 20:22:31 +00:00
|
|
|
Scroll( x/ppux, y/ppuy );
|
2007-08-22 05:11:01 +00:00
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
void WinEDA_DrawPanel::OnSize( wxSizeEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-02-22 16:45:35 +00:00
|
|
|
if( IsShown() )
|
|
|
|
{
|
|
|
|
INSTALL_DC( dc, this ); // Update boundary box.
|
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
/** Function SetBoundaryBox()
|
2010-02-11 19:57:47 +00:00
|
|
|
* Set the clip box to the current displayed rectangle dimensions.
|
|
|
|
*
|
|
|
|
* When using wxDC for scaling, the clip box coordinates are in drawing (logical)
|
|
|
|
* units. In other words, the area of the drawing that will be displayed on the
|
|
|
|
* screen. When using Kicad's scaling, the clip box coordinates are in screen
|
|
|
|
* (device) units according to the current scroll position.
|
|
|
|
*
|
|
|
|
* @param dc - The device context use for drawing with the correct scale and
|
|
|
|
* offsets already configured. See DoPrepareDC().
|
2007-12-09 09:00:15 +00:00
|
|
|
*/
|
2010-02-08 18:15:42 +00:00
|
|
|
void WinEDA_DrawPanel::SetBoundaryBox( wxDC* dc )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-02-08 18:15:42 +00:00
|
|
|
wxASSERT( dc != NULL );
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
BASE_SCREEN* Screen = GetScreen();;
|
2008-03-10 08:14:20 +00:00
|
|
|
|
|
|
|
if( !Screen )
|
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
Screen->m_StartVisu = CalcUnscrolledPosition( wxPoint( 0, 0 ) );
|
|
|
|
m_ClipBox.SetOrigin( wxPoint( 0, 0 ) );
|
2007-08-22 05:11:01 +00:00
|
|
|
m_ClipBox.SetSize( GetClientSize() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
int scrollX, scrollY;
|
|
|
|
|
|
|
|
#ifdef USE_WX_ZOOM
|
2010-02-22 16:45:35 +00:00
|
|
|
double scalar = Screen->GetScalingFactor();
|
|
|
|
scrollX = wxRound( Screen->GetGridSize().x * scalar );
|
|
|
|
scrollY = wxRound( Screen->GetGridSize().y * scalar );
|
2007-05-06 16:03:28 +00:00
|
|
|
#else
|
2010-02-08 18:15:42 +00:00
|
|
|
scrollX = wxRound( Screen->Scale( Screen->GetGridSize().x ) );
|
|
|
|
scrollY = wxRound( Screen->Scale( Screen->GetGridSize().y ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
m_scrollIncrementX = MAX( GetClientSize().x / 8, scrollX );
|
|
|
|
m_scrollIncrementY = MAX( GetClientSize().y / 8, scrollY );
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_WX_ZOOM
|
|
|
|
/* Using wxDC scaling requires clipping in drawing (logical) units. */
|
2010-02-22 16:45:35 +00:00
|
|
|
m_ClipBox.SetOrigin( CalcUnscrolledPosition( wxPoint( 0, 0 ) ) );
|
|
|
|
m_ClipBox.Inflate( CLIP_BOX_PADDING );
|
|
|
|
m_ClipBox.m_Pos.x = wxRound( (double) m_ClipBox.m_Pos.x / scalar );
|
|
|
|
m_ClipBox.m_Pos.y = wxRound( (double) m_ClipBox.m_Pos.y / scalar );
|
|
|
|
m_ClipBox.m_Pos += Screen->m_DrawOrg;
|
|
|
|
m_ClipBox.m_Size.x = wxRound( (double) m_ClipBox.m_Size.x / scalar );
|
|
|
|
m_ClipBox.m_Size.y = wxRound( (double) m_ClipBox.m_Size.y / scalar );
|
2010-02-08 18:15:42 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
Screen->m_ScrollbarPos.x = GetScrollPos( wxHORIZONTAL );
|
|
|
|
Screen->m_ScrollbarPos.y = GetScrollPos( wxVERTICAL );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
void WinEDA_DrawPanel::EraseScreen( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
GRSetDrawMode( DC, GR_COPY );
|
2008-03-10 15:51:44 +00:00
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
GRSFilledRect( &m_ClipBox, DC, m_ClipBox.GetX(), m_ClipBox.GetY(),
|
|
|
|
m_ClipBox.GetRight(), m_ClipBox.GetBottom(),
|
2009-12-30 18:06:12 +00:00
|
|
|
0, g_DrawBgColor, g_DrawBgColor );
|
2010-02-22 16:45:35 +00:00
|
|
|
|
|
|
|
/* Set to one (1) to draw bounding box validate bounding box calculation. */
|
|
|
|
#if DEBUG_SHOW_CLIP_RECT
|
|
|
|
EDA_Rect bBox = m_ClipBox;
|
|
|
|
bBox.Inflate( -DC->DeviceToLogicalXRel( 1 ) );
|
|
|
|
GRRect( NULL, DC, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
void WinEDA_DrawPanel::DoPrepareDC(wxDC& dc)
|
|
|
|
{
|
|
|
|
#ifdef USE_WX_ZOOM
|
|
|
|
if( GetScreen() != NULL )
|
|
|
|
{
|
|
|
|
double scale = GetScreen()->GetScalingFactor();
|
2010-02-22 16:45:35 +00:00
|
|
|
dc.SetUserScale( scale, scale );
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
wxPoint pt = CalcUnscrolledPosition( wxPoint( 0, 0 ) );
|
|
|
|
dc.SetDeviceOrigin( -pt.x, -pt.y );
|
|
|
|
pt = GetScreen()->m_DrawOrg;
|
|
|
|
dc.SetLogicalOrigin( pt.x, pt.y );
|
2010-02-08 18:15:42 +00:00
|
|
|
}
|
2008-12-30 19:18:56 +00:00
|
|
|
#endif
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
GRResetPenAndBrush( &dc );
|
|
|
|
dc.SetBackgroundMode( wxTRANSPARENT );
|
|
|
|
SetBoundaryBox( &dc );
|
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
|
2008-03-06 01:46:30 +00:00
|
|
|
{
|
2009-06-26 17:24:32 +00:00
|
|
|
if( GetScreen() == NULL )
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
INSTALL_PAINTDC( paintDC, this );
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
/* wxAutoBufferedPaintDC does not work correctly by setting the user scale and
|
|
|
|
* logcial offset. The bitmap coordinates and scaling are not effected by the
|
|
|
|
* code below. It appears that the wxBufferPaintDC needs to be created with the
|
|
|
|
* wxBUFFER_VIRTUAL_AREA set and the wirtual method wxWindow::PrepareDC() needs
|
|
|
|
* to be overridden to set up the buffered paint DC properly. The bitmap grid
|
|
|
|
* draw code ( see DrawGrid() below ) will have to be fixed before this can be
|
|
|
|
* implemented.
|
|
|
|
*/
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2010-02-10 21:39:32 +00:00
|
|
|
EDA_Rect tmp = m_ClipBox;
|
2008-03-06 01:46:30 +00:00
|
|
|
|
2010-02-10 21:39:32 +00:00
|
|
|
// Get the union of all rectangles in the update region.
|
|
|
|
wxRect PaintClipBox = GetUpdateRegion().GetBox();
|
2008-03-06 01:46:30 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
#if DEBUG_DUMP_CLIP_COORDS
|
2010-02-08 18:15:42 +00:00
|
|
|
wxLogDebug( wxT( "1) PaintClipBox=(%d, %d, %d, %d), m_ClipBox=(%d, %d, %d, %d)" ),
|
|
|
|
PaintClipBox.x, PaintClipBox.y, PaintClipBox.width, PaintClipBox.height,
|
|
|
|
m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y, m_ClipBox.m_Size.x, m_ClipBox.m_Size.y );
|
2008-03-06 01:46:30 +00:00
|
|
|
#endif
|
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
#if defined( USE_WX_ZOOM )
|
|
|
|
/* When using wxDC scaling the clipping region coordinates are in drawing
|
|
|
|
* (logical) units.
|
|
|
|
*/
|
2010-02-22 16:45:35 +00:00
|
|
|
double scalar = GetScreen()->GetScalingFactor();
|
|
|
|
m_ClipBox.m_Pos = CalcUnscrolledPosition( PaintClipBox.GetPosition() );
|
|
|
|
m_ClipBox.m_Size = PaintClipBox.GetSize();
|
|
|
|
m_ClipBox.Inflate( CLIP_BOX_PADDING );
|
|
|
|
m_ClipBox.m_Pos.x = wxRound( (double) m_ClipBox.m_Pos.x / scalar );
|
|
|
|
m_ClipBox.m_Pos.y = wxRound( (double) m_ClipBox.m_Pos.y / scalar );
|
|
|
|
m_ClipBox.m_Pos += GetScreen()->m_DrawOrg;
|
|
|
|
m_ClipBox.m_Size.x = wxRound( (double) m_ClipBox.m_Size.x / scalar );
|
|
|
|
m_ClipBox.m_Size.y = wxRound( (double) m_ClipBox.m_Size.y / scalar );
|
2010-02-10 21:39:32 +00:00
|
|
|
PaintClipBox = m_ClipBox;
|
2008-03-06 01:46:30 +00:00
|
|
|
#else
|
2010-02-11 19:57:47 +00:00
|
|
|
/* When using Kicad's scaling the clipping region coordinates are in screen
|
2010-02-08 18:15:42 +00:00
|
|
|
* (device) units.
|
|
|
|
*/
|
2008-03-06 01:46:30 +00:00
|
|
|
m_ClipBox.SetX( PaintClipBox.GetX() );
|
|
|
|
m_ClipBox.SetY( PaintClipBox.GetY() );
|
|
|
|
m_ClipBox.SetWidth( PaintClipBox.GetWidth() );
|
|
|
|
m_ClipBox.SetHeight( PaintClipBox.GetHeight() );
|
|
|
|
|
2009-07-10 12:29:31 +00:00
|
|
|
// Be sure the drawpanel clipbox is bigger than the region to repair:
|
2010-01-17 14:20:29 +00:00
|
|
|
m_ClipBox.Inflate( 1 ); // Give it one pixel more in each direction
|
2010-02-10 21:39:32 +00:00
|
|
|
#endif
|
2008-03-06 01:46:30 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
#if DEBUG_DUMP_CLIP_COORDS
|
2010-02-08 18:15:42 +00:00
|
|
|
wxLogDebug( wxT( "2) PaintClipBox=(%d, %d, %d, %d), m_ClipBox=(%d, %d, %d, %d)" ),
|
|
|
|
PaintClipBox.x, PaintClipBox.y, PaintClipBox.width, PaintClipBox.height,
|
|
|
|
m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y, m_ClipBox.m_Size.x, m_ClipBox.m_Size.y );
|
2008-03-06 01:46:30 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-10 13:33:12 +00:00
|
|
|
// call ~wxDCClipper() before ~wxPaintDC()
|
|
|
|
{
|
|
|
|
wxDCClipper dcclip( paintDC, PaintClipBox );
|
2009-04-09 18:39:39 +00:00
|
|
|
ReDraw( &paintDC, true );
|
2008-03-10 13:33:12 +00:00
|
|
|
}
|
2008-03-06 01:46:30 +00:00
|
|
|
|
|
|
|
m_ClipBox = tmp;
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2008-03-10 08:14:20 +00:00
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
void WinEDA_DrawPanel::ReDraw( wxDC* DC, bool erasebg )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
BASE_SCREEN* Screen = GetScreen();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
if( Screen == NULL )
|
2007-08-15 02:43:57 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
if( ( g_DrawBgColor != WHITE ) && ( g_DrawBgColor != BLACK ) )
|
2007-08-15 02:43:57 +00:00
|
|
|
g_DrawBgColor = BLACK;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
if( g_DrawBgColor == WHITE )
|
|
|
|
{
|
|
|
|
g_XorMode = GR_NXOR;
|
|
|
|
g_GhostColor = BLACK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_XorMode = GR_XOR;
|
|
|
|
g_GhostColor = WHITE;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
if( erasebg )
|
2009-04-15 19:53:41 +00:00
|
|
|
EraseScreen( DC );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
SetBackgroundColour( wxColour( ColorRefs[g_DrawBgColor].m_Red,
|
2008-08-26 09:06:26 +00:00
|
|
|
ColorRefs[g_DrawBgColor].m_Green,
|
|
|
|
ColorRefs[g_DrawBgColor].m_Blue ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
GRResetPenAndBrush( DC );
|
|
|
|
|
|
|
|
DC->SetBackground( *wxBLACK_BRUSH );
|
|
|
|
DC->SetBackgroundMode( wxTRANSPARENT );
|
|
|
|
m_Parent->RedrawActiveWindow( DC, erasebg );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
/** Function DrawBackGround
|
|
|
|
* @param DC = current Device Context
|
2010-01-17 14:20:29 +00:00
|
|
|
* Draws (if allowed) :
|
|
|
|
* the grid
|
|
|
|
* X and Y axis
|
|
|
|
* X and Y auxiliary axis
|
|
|
|
*/
|
|
|
|
void WinEDA_DrawPanel::DrawBackGround( wxDC* DC )
|
|
|
|
{
|
|
|
|
int axis_color = BLUE;
|
|
|
|
BASE_SCREEN* screen = GetScreen();
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, GR_COPY );
|
|
|
|
|
2010-02-01 21:23:27 +00:00
|
|
|
if( m_Parent->IsGridVisible() )
|
2010-01-17 14:20:29 +00:00
|
|
|
DrawGrid( DC );
|
|
|
|
|
|
|
|
/* Draw axis */
|
|
|
|
if( m_Parent->m_Draw_Axis )
|
|
|
|
{
|
|
|
|
/* Draw the Y axis */
|
|
|
|
GRDashedLine( &m_ClipBox, DC, 0, -screen->ReturnPageSize().y,
|
|
|
|
0, screen->ReturnPageSize().y, 0, axis_color );
|
|
|
|
|
|
|
|
/* Draw the X axis */
|
|
|
|
GRDashedLine( &m_ClipBox, DC, -screen->ReturnPageSize().x, 0,
|
|
|
|
screen->ReturnPageSize().x, 0, 0, axis_color );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Parent->m_Draw_Auxiliary_Axis )
|
|
|
|
DrawAuxiliaryAxis( DC, GR_COPY );
|
2010-07-13 10:42:32 +00:00
|
|
|
|
|
|
|
if( m_Parent->m_Draw_Grid_Axis )
|
|
|
|
DrawGridAxis( DC, GR_COPY );
|
2010-01-17 14:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Function DrawGrid
|
|
|
|
* @param DC = current Device Context
|
2007-12-09 09:00:15 +00:00
|
|
|
* draws the grid
|
|
|
|
* - the grid is drawn only if the zoom level allows a good visibility
|
2009-11-23 15:16:50 +00:00
|
|
|
* - the grid is always centered on the screen center
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2010-01-17 14:20:29 +00:00
|
|
|
void WinEDA_DrawPanel::DrawGrid( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
BASE_SCREEN* screen = GetScreen();
|
2010-01-17 14:20:29 +00:00
|
|
|
int ii, jj, xg, yg;
|
2009-02-11 15:49:28 +00:00
|
|
|
wxRealPoint screen_grid_size;
|
2007-08-22 05:11:01 +00:00
|
|
|
wxSize size;
|
|
|
|
wxPoint org;
|
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
/* The grid must be visible. this is possible only is grid value
|
|
|
|
* and zoom value are sufficient
|
|
|
|
*/
|
2009-10-14 19:43:31 +00:00
|
|
|
screen_grid_size = screen->GetGridSize();
|
2010-02-08 18:15:42 +00:00
|
|
|
org = CalcUnscrolledPosition( wxPoint( 0, 0 ) );
|
|
|
|
screen->m_StartVisu = org;
|
|
|
|
size = GetClientSize();
|
|
|
|
|
|
|
|
#ifdef USE_WX_ZOOM
|
|
|
|
if( DC->LogicalToDeviceXRel( wxRound( screen_grid_size.x ) ) < 5
|
|
|
|
|| DC->LogicalToDeviceXRel( wxRound( screen_grid_size.y ) ) < 5 )
|
|
|
|
return;
|
2009-02-26 20:06:51 +00:00
|
|
|
|
2010-02-11 19:57:47 +00:00
|
|
|
org = m_ClipBox.m_Pos;
|
|
|
|
size = m_ClipBox.m_Size;
|
2010-02-08 18:15:42 +00:00
|
|
|
#else
|
2010-01-17 14:20:29 +00:00
|
|
|
wxRealPoint dgrid = screen_grid_size;
|
2009-02-11 15:49:28 +00:00
|
|
|
screen->Scale( dgrid ); // dgrid = grid size in pixels
|
2010-01-17 14:20:29 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// if the grid size is small ( < 5 pixels) do not display all points
|
2010-02-08 18:15:42 +00:00
|
|
|
if( dgrid.x < 5 )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
2009-02-11 15:49:28 +00:00
|
|
|
screen_grid_size.x *= 2;
|
|
|
|
dgrid.x *= 2;
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
2009-02-11 15:49:28 +00:00
|
|
|
if( dgrid.x < 5 )
|
2010-01-17 14:20:29 +00:00
|
|
|
return; // The grid is too small: do not show it
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2009-02-11 15:49:28 +00:00
|
|
|
if( dgrid.y < 5 )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
2009-02-11 15:49:28 +00:00
|
|
|
screen_grid_size.y *= 2;
|
|
|
|
dgrid.y *= 2;
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
2009-02-11 15:49:28 +00:00
|
|
|
if( dgrid.y < 5 )
|
2010-01-17 14:20:29 +00:00
|
|
|
return; // The grid is too small
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
screen->Unscale( size );
|
2009-01-29 14:26:20 +00:00
|
|
|
screen->Unscale( org );
|
2009-01-17 20:31:19 +00:00
|
|
|
org += screen->m_DrawOrg;
|
2009-04-09 18:39:39 +00:00
|
|
|
#endif
|
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
m_Parent->PutOnGrid( &org );
|
2010-02-01 21:23:27 +00:00
|
|
|
GRSetColorPen( DC, m_Parent->GetGridColor() );
|
2010-01-17 14:20:29 +00:00
|
|
|
int xpos, ypos;
|
2010-01-13 20:03:33 +00:00
|
|
|
|
2010-01-14 08:55:45 +00:00
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
// Draw grid: the best algorithm depend on the platform.
|
|
|
|
// under macOSX, the first method is better
|
|
|
|
// under window, the second method is better
|
|
|
|
// Under linux, to be tested (could be depend on linux versions
|
|
|
|
// so perhaps could be necessary to set this option at run time.
|
2010-01-14 08:55:45 +00:00
|
|
|
|
2010-01-18 19:33:45 +00:00
|
|
|
#if defined( __WXMAC__ )
|
2010-01-24 16:27:36 +00:00
|
|
|
wxWindowUpdateLocker( this ); // under macOSX: drawings are faster with this
|
|
|
|
#endif
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
|
|
|
|
/* The bitmap grid drawing code below cannot be used when wxDC scaling is used
|
|
|
|
* as it does not scale the grid bitmap properly. This needs to be fixed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined( __WXMAC__ ) || defined( USE_WX_ZOOM )
|
2010-01-17 14:20:29 +00:00
|
|
|
// Use a pixel based draw to display grid
|
|
|
|
// There is a lot of calls, so the cost is hight
|
|
|
|
// and grid is slowly drawn on some platforms
|
|
|
|
for( ii = 0; ; ii++ )
|
|
|
|
{
|
|
|
|
xg = wxRound( ii * screen_grid_size.x );
|
|
|
|
if( xg > size.x )
|
|
|
|
break;
|
|
|
|
xpos = org.x + xg;
|
|
|
|
xpos = GRMapX( xpos );
|
2010-01-13 20:03:33 +00:00
|
|
|
for( jj = 0; ; jj++ )
|
|
|
|
{
|
2010-01-17 14:20:29 +00:00
|
|
|
yg = wxRound( jj * screen_grid_size.y );
|
2010-01-13 20:03:33 +00:00
|
|
|
if( yg > size.y )
|
|
|
|
break;
|
|
|
|
ypos = org.y + yg;
|
2010-01-17 14:20:29 +00:00
|
|
|
DC->DrawPoint( xpos, GRMapY( ypos ) );
|
2010-01-13 20:03:33 +00:00
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* Currently on test: Use a fast way to draw the grid
|
|
|
|
* But this is fast only if the Blit function is fast. Not true on all platforms
|
|
|
|
* a grid column is drawn; and then copied to others grid columns
|
|
|
|
* this is possible because the grid is drawn only after clearing the screen.
|
|
|
|
*
|
2010-01-24 16:27:36 +00:00
|
|
|
* A first grid column is drawn in a temporary bitmap,
|
|
|
|
* and after is duplicated using the Blit function
|
2010-01-17 14:20:29 +00:00
|
|
|
* (copy from a screen area to an other screen area)
|
|
|
|
*/
|
|
|
|
|
|
|
|
wxSize screenSize = GetClientSize();
|
2010-01-24 16:27:36 +00:00
|
|
|
wxMemoryDC tmpDC;
|
2010-02-08 18:15:42 +00:00
|
|
|
wxBitmap tmpBM( 1, screenSize.y );
|
2010-01-24 16:27:36 +00:00
|
|
|
tmpDC.SelectObject( tmpBM );
|
|
|
|
GRSetColorPen( &tmpDC, g_DrawBgColor );
|
|
|
|
tmpDC.DrawLine( 0, 0, 0, screenSize.y-1 ); // init background
|
2010-02-01 21:23:27 +00:00
|
|
|
GRSetColorPen( &tmpDC, m_Parent->GetGridColor() );
|
2010-01-24 16:27:36 +00:00
|
|
|
for( jj = 0; ; jj++ ) // draw grid points
|
2010-01-17 14:20:29 +00:00
|
|
|
{
|
|
|
|
yg = wxRound( jj * screen_grid_size.y );
|
2010-01-24 16:27:36 +00:00
|
|
|
ypos = screen->Scale( yg );
|
|
|
|
if( ypos > screenSize.y )
|
2010-01-17 14:20:29 +00:00
|
|
|
break;
|
2010-01-24 16:27:36 +00:00
|
|
|
tmpDC.DrawPoint( 0, ypos );
|
2010-01-17 14:20:29 +00:00
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
ypos = GRMapY( org.y );
|
2010-01-24 16:27:36 +00:00
|
|
|
for( ii = 0; ; ii++ )
|
2010-01-17 14:20:29 +00:00
|
|
|
{
|
|
|
|
xg = wxRound( ii * screen_grid_size.x );
|
|
|
|
if( xg > size.x )
|
|
|
|
break;
|
|
|
|
xpos = GRMapX( org.x + xg );
|
2010-01-24 16:27:36 +00:00
|
|
|
if( xpos < m_ClipBox.GetOrigin().x) // column not in active screen area.
|
2010-01-17 14:20:29 +00:00
|
|
|
if( xpos > m_ClipBox.GetEnd().x) // end of active area reached.
|
|
|
|
break;
|
2010-01-24 16:27:36 +00:00
|
|
|
DC->Blit( xpos, ypos, 1, screenSize.y, &tmpDC, 0, 0 );
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
/** function DrawAuxiliaryAxis
|
2007-12-09 09:00:15 +00:00
|
|
|
* Draw the Auxiliary Axis, used in pcbnew which as origin coordinates
|
|
|
|
* for gerber and excellon files
|
2010-01-17 14:20:29 +00:00
|
|
|
* @param DC = current Device Context
|
2007-12-09 09:00:15 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void WinEDA_DrawPanel::DrawAuxiliaryAxis( wxDC* DC, int drawmode )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-01-17 14:20:29 +00:00
|
|
|
if( m_Parent->m_Auxiliary_Axis_Position == wxPoint( 0, 0 ) )
|
2007-08-22 05:11:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int Color = DARKRED;
|
|
|
|
BASE_SCREEN* screen = GetScreen();
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, drawmode );
|
|
|
|
|
2007-10-06 16:16:48 +00:00
|
|
|
/* Draw the Y axis */
|
2007-08-22 05:11:01 +00:00
|
|
|
GRDashedLine( &m_ClipBox, DC,
|
2008-12-05 16:03:05 +00:00
|
|
|
m_Parent->m_Auxiliary_Axis_Position.x,
|
|
|
|
-screen->ReturnPageSize().y,
|
|
|
|
m_Parent->m_Auxiliary_Axis_Position.x,
|
|
|
|
screen->ReturnPageSize().y,
|
2008-08-26 09:06:26 +00:00
|
|
|
0, Color );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2007-10-06 16:16:48 +00:00
|
|
|
/* Draw the X axis */
|
2007-08-22 05:11:01 +00:00
|
|
|
GRDashedLine( &m_ClipBox, DC,
|
2008-12-05 16:03:05 +00:00
|
|
|
-screen->ReturnPageSize().x,
|
|
|
|
m_Parent->m_Auxiliary_Axis_Position.y,
|
|
|
|
screen->ReturnPageSize().x,
|
|
|
|
m_Parent->m_Auxiliary_Axis_Position.y,
|
2008-08-26 09:06:26 +00:00
|
|
|
0, Color );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
/********************************************************************/
|
|
|
|
void WinEDA_DrawPanel::DrawGridAxis( wxDC* DC, int drawmode )
|
|
|
|
/********************************************************************/
|
|
|
|
{
|
|
|
|
BASE_SCREEN* screen = GetScreen();
|
|
|
|
if( !m_Parent->m_Draw_Grid_Axis
|
|
|
|
|| ( screen->m_GridOrigin.x == 0
|
|
|
|
&& screen->m_GridOrigin.y == 0 ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int Color = m_Parent->GetGridColor();
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, drawmode );
|
|
|
|
|
|
|
|
/* Draw the Y axis */
|
|
|
|
GRDashedLine( &m_ClipBox, DC,
|
|
|
|
screen->m_GridOrigin.x,
|
|
|
|
-screen->ReturnPageSize().y,
|
|
|
|
screen->m_GridOrigin.x,
|
|
|
|
screen->ReturnPageSize().y,
|
|
|
|
0, Color );
|
|
|
|
|
|
|
|
/* Draw the X axis */
|
|
|
|
GRDashedLine( &m_ClipBox, DC,
|
|
|
|
-screen->ReturnPageSize().x,
|
|
|
|
screen->m_GridOrigin.y,
|
|
|
|
screen->ReturnPageSize().x,
|
|
|
|
screen->m_GridOrigin.y,
|
|
|
|
0, Color );
|
|
|
|
}
|
2007-08-15 02:43:57 +00:00
|
|
|
|
2007-10-07 18:24:15 +00:00
|
|
|
/** Build and display a Popup menu on a right mouse button click
|
|
|
|
* @return true if a popup menu is shown, or false
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
bool WinEDA_DrawPanel::OnRightClick( wxMouseEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
wxPoint pos;
|
|
|
|
wxMenu MasterMenu;
|
|
|
|
|
2009-01-17 20:31:19 +00:00
|
|
|
pos = event.GetPosition();
|
2007-12-09 09:00:15 +00:00
|
|
|
|
|
|
|
if( !m_Parent->OnRightClick( pos, &MasterMenu ) )
|
|
|
|
return false;
|
|
|
|
|
2010-02-14 18:14:33 +00:00
|
|
|
m_Parent->AddMenuZoomAndGrid( &MasterMenu );
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
m_IgnoreMouseEvents = TRUE;
|
|
|
|
PopupMenu( &MasterMenu, pos );
|
|
|
|
MouseToCursorSchema();
|
2009-12-29 10:35:11 +00:00
|
|
|
m_IgnoreMouseEvents = false;
|
2007-12-09 09:00:15 +00:00
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// Called when the canvas receives a mouse event leaving frame.
|
2007-08-22 05:11:01 +00:00
|
|
|
void WinEDA_DrawPanel::OnMouseLeaving( wxMouseEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
if( ManageCurseur == NULL ) // No command in progress.
|
2009-12-29 10:35:11 +00:00
|
|
|
m_AutoPAN_Request = false;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
if( !m_AutoPAN_Enable || !m_AutoPAN_Request || m_IgnoreMouseEvents )
|
|
|
|
return;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// Auto pan if mouse is leave working area:
|
2007-08-22 05:11:01 +00:00
|
|
|
wxSize size = GetClientSize();
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
if( ( size.x < event.GetX() ) || ( size.y < event.GetY() )
|
2010-01-17 14:20:29 +00:00
|
|
|
|| ( event.GetX() <= 0) || ( event.GetY() <= 0 ) )
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_POPUP_ZOOM_CENTER );
|
|
|
|
cmd.SetEventObject( this );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-19 13:51:48 +00:00
|
|
|
/*
|
|
|
|
* Handle mouse wheel events.
|
|
|
|
*
|
|
|
|
* The mouse wheel is used to provide support for zooming and panning. This
|
2009-04-05 20:49:15 +00:00
|
|
|
* is accomplished by converting mouse wheel events in pseudo menu command
|
2008-12-19 13:51:48 +00:00
|
|
|
* events.
|
|
|
|
*/
|
|
|
|
void WinEDA_DrawPanel::OnMouseWheel( wxMouseEvent& event )
|
|
|
|
{
|
2010-01-15 10:02:47 +00:00
|
|
|
if( m_IgnoreMouseEvents )
|
|
|
|
return;
|
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
wxRect rect = wxRect( wxPoint( 0, 0 ), GetClientSize() );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
/* Ignore scroll events if the cursor is outside the drawing area. */
|
|
|
|
if( event.GetWheelRotation() == 0 || !GetParent()->IsEnabled()
|
2010-01-17 14:20:29 +00:00
|
|
|
|| !rect.Contains( event.GetPosition() ) )
|
2008-12-19 13:51:48 +00:00
|
|
|
{
|
2009-12-29 10:35:11 +00:00
|
|
|
#if 0
|
2009-05-21 17:42:42 +00:00
|
|
|
wxLogDebug( wxT( "OnMouseWheel() position(%d, %d) " ) \
|
|
|
|
wxT( "rectangle(%d, %d, %d, %d)" ),
|
2009-01-17 20:31:19 +00:00
|
|
|
event.GetPosition().x, event.GetPosition().y,
|
|
|
|
rect.x, rect.y, rect.width, rect.height );
|
2009-12-29 10:35:11 +00:00
|
|
|
#endif
|
2008-12-19 13:51:48 +00:00
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
GetScreen()->m_Curseur =
|
|
|
|
CursorRealPosition( CalcUnscrolledPosition( event.GetPosition() ) );
|
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
|
2008-12-19 13:51:48 +00:00
|
|
|
cmd.SetEventObject( this );
|
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
// This is a zoom in or out command
|
2008-12-19 13:51:48 +00:00
|
|
|
if( event.GetWheelRotation() > 0 )
|
|
|
|
{
|
|
|
|
if( event.ShiftDown() && !event.ControlDown() )
|
|
|
|
cmd.SetId( ID_PAN_UP );
|
|
|
|
else if( event.ControlDown() && !event.ShiftDown() )
|
|
|
|
cmd.SetId( ID_PAN_LEFT );
|
|
|
|
else
|
|
|
|
cmd.SetId( ID_POPUP_ZOOM_IN );
|
|
|
|
}
|
2010-01-17 14:20:29 +00:00
|
|
|
else if( event.GetWheelRotation() < 0 )
|
2008-12-19 13:51:48 +00:00
|
|
|
{
|
|
|
|
if( event.ShiftDown() && !event.ControlDown() )
|
|
|
|
cmd.SetId( ID_PAN_DOWN );
|
|
|
|
else if( event.ControlDown() && !event.ShiftDown() )
|
|
|
|
cmd.SetId( ID_PAN_RIGHT );
|
|
|
|
else
|
|
|
|
cmd.SetId( ID_POPUP_ZOOM_OUT );
|
|
|
|
}
|
|
|
|
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
2010-02-22 16:45:35 +00:00
|
|
|
event.Skip();
|
2008-12-19 13:51:48 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// Called when the canvas receives a mouse event.
|
|
|
|
void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
int localrealbutt = 0, localbutt = 0, localkey = 0;
|
|
|
|
BASE_SCREEN* screen = GetScreen();
|
|
|
|
static WinEDA_DrawPanel* LastPanel;
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2008-03-10 08:14:20 +00:00
|
|
|
if( !screen )
|
|
|
|
return;
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
/* Adjust value to filter mouse displacement before consider the drag
|
|
|
|
* mouse is really a drag command, not just a movement while click
|
|
|
|
*/
|
|
|
|
#define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5
|
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
/* Count the drag events. Used to filter mouse moves before starting a
|
|
|
|
* block command. A block command can be started only if MinDragEventCount >
|
|
|
|
* MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND in order to avoid spurious block
|
|
|
|
* commands. */
|
2009-11-23 15:16:50 +00:00
|
|
|
static int MinDragEventCount;
|
2007-08-22 05:11:01 +00:00
|
|
|
if( event.Leaving() || event.Entering() )
|
|
|
|
{
|
|
|
|
m_CanStartBlock = -1;
|
|
|
|
}
|
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
if( ManageCurseur == NULL ) // No command in progress
|
2009-12-29 10:35:11 +00:00
|
|
|
m_AutoPAN_Request = false;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
if( m_Parent->m_FrameIsActive )
|
|
|
|
SetFocus();
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( !event.IsButton() && !event.Moving()
|
|
|
|
&& !event.Dragging() && !localkey )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( event.RightDown() )
|
|
|
|
{
|
2007-12-09 09:00:15 +00:00
|
|
|
OnRightClick( event );
|
2007-09-11 04:11:48 +00:00
|
|
|
return;
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_IgnoreMouseEvents )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( event.LeftIsDown() )
|
|
|
|
localrealbutt |= GR_M_LEFT_DOWN;
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
if( event.MiddleIsDown() )
|
|
|
|
localrealbutt |= GR_M_MIDDLE_DOWN;
|
|
|
|
|
|
|
|
if( event.LeftDown() )
|
|
|
|
localbutt = GR_M_LEFT_DOWN;
|
|
|
|
|
|
|
|
if( event.ButtonDClick( 1 ) )
|
|
|
|
localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK;
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
if( event.MiddleDown() )
|
|
|
|
localbutt = GR_M_MIDDLE_DOWN;
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
if( event.ButtonDClick( 2 ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
; // Unused
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
localrealbutt |= localbutt; /* compensation default wxGTK */
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
/* Compute the cursor position in screen (device) units. */
|
|
|
|
screen->m_MousePositionInPixels = CalcUnscrolledPosition( event.GetPosition() );
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
/* Compute the cursor position in drawing (logical) units. */
|
2009-11-23 15:16:50 +00:00
|
|
|
screen->m_MousePosition =
|
2010-02-08 18:15:42 +00:00
|
|
|
CursorRealPosition( CalcUnscrolledPosition( event.GetPosition() ) );
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2009-12-20 19:48:58 +00:00
|
|
|
INSTALL_DC( DC, this );
|
2009-12-19 16:10:25 +00:00
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
int kbstat = 0;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
DC.SetBackground( *wxBLACK_BRUSH );
|
|
|
|
|
|
|
|
g_KeyPressed = localkey;
|
|
|
|
|
|
|
|
if( event.ShiftDown() )
|
|
|
|
kbstat |= GR_KB_SHIFT;
|
|
|
|
if( event.ControlDown() )
|
|
|
|
kbstat |= GR_KB_CTRL;
|
|
|
|
if( event.AltDown() )
|
|
|
|
kbstat |= GR_KB_ALT;
|
|
|
|
|
|
|
|
g_MouseOldButtons = localrealbutt;
|
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
// Calling Double Click and Click functions :
|
2010-01-17 14:20:29 +00:00
|
|
|
if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
|
2007-12-09 09:00:15 +00:00
|
|
|
{
|
2007-08-22 05:11:01 +00:00
|
|
|
m_Parent->OnLeftDClick( &DC, screen->m_MousePositionInPixels );
|
2008-08-26 09:06:26 +00:00
|
|
|
|
|
|
|
// inhibit a response to the mouse left button release,
|
2009-11-23 15:16:50 +00:00
|
|
|
// because we have a double click, and we do not want a new
|
|
|
|
// OnLeftClick command at end of this Double Click
|
2008-08-26 09:06:26 +00:00
|
|
|
s_IgnoreNextLeftButtonRelease = true;
|
2007-12-09 09:00:15 +00:00
|
|
|
}
|
2007-10-09 12:29:02 +00:00
|
|
|
else if( event.LeftUp() )
|
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
// A block command is in progress: a left up is the end of block
|
|
|
|
// or this is the end of a double click, already seen
|
|
|
|
if( screen->m_BlockLocate.m_State==STATE_NO_BLOCK
|
|
|
|
&& !s_IgnoreNextLeftButtonRelease )
|
2007-12-09 09:00:15 +00:00
|
|
|
m_Parent->OnLeftClick( &DC, screen->m_MousePositionInPixels );
|
|
|
|
|
2008-08-26 09:06:26 +00:00
|
|
|
s_IgnoreNextLeftButtonRelease = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !event.LeftIsDown() )
|
|
|
|
{
|
|
|
|
/* be sure there is a response to a left button release command
|
2009-11-23 15:16:50 +00:00
|
|
|
* even when a LeftUp event is not seen. This happens when a
|
|
|
|
* double click opens a dialog box, and the release mouse button
|
|
|
|
* is made when the dialog box is open.
|
2008-08-26 09:06:26 +00:00
|
|
|
*/
|
|
|
|
s_IgnoreNextLeftButtonRelease = false;
|
2007-10-09 12:29:02 +00:00
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
if( event.ButtonUp( 2 )
|
2010-01-17 14:20:29 +00:00
|
|
|
&& (screen->m_BlockLocate.m_State == STATE_NO_BLOCK) )
|
2007-12-09 09:00:15 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
// The middle button has been released, with no block command:
|
2009-01-07 15:59:49 +00:00
|
|
|
// We use it for a zoom center at cursor position command
|
|
|
|
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
ID_POPUP_ZOOM_CENTER );
|
|
|
|
cmd.SetEventObject( this );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* Calling the general function on mouse changes (and pseudo key commands) */
|
2007-08-22 05:11:01 +00:00
|
|
|
m_Parent->GeneralControle( &DC, screen->m_MousePositionInPixels );
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************/
|
|
|
|
/* Control of block commands : */
|
|
|
|
/*******************************/
|
|
|
|
|
|
|
|
// Command block can't start if mouse is dragging a new panel
|
|
|
|
if( LastPanel != this )
|
2008-01-18 20:27:14 +00:00
|
|
|
{
|
|
|
|
MinDragEventCount = 0;
|
|
|
|
m_CanStartBlock = -1;
|
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2008-01-18 20:27:14 +00:00
|
|
|
/* A new command block can start after a release buttons
|
2009-04-05 20:49:15 +00:00
|
|
|
* and if the drag is enough
|
2009-11-23 15:16:50 +00:00
|
|
|
* This is to avoid a false start block when a dialog box is dismissed,
|
2009-04-05 20:49:15 +00:00
|
|
|
* or when changing panels in hierarchy navigation
|
2008-01-18 20:27:14 +00:00
|
|
|
* or when clicking while and moving mouse
|
|
|
|
*/
|
2007-08-22 05:11:01 +00:00
|
|
|
if( !event.LeftIsDown() && !event.MiddleIsDown() )
|
|
|
|
{
|
2008-01-18 20:27:14 +00:00
|
|
|
MinDragEventCount = 0;
|
|
|
|
m_CanStartBlock = 0;
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Remember the last cursor position when a drag mouse starts
|
2009-04-05 20:49:15 +00:00
|
|
|
* this is the last position ** before ** clicking a button
|
2009-11-23 15:16:50 +00:00
|
|
|
* this is useful to start a block command from the point where the
|
|
|
|
* mouse was clicked first
|
|
|
|
* (a filter creates a delay for the real block command start, and
|
|
|
|
* we must remember this point)
|
2008-01-18 20:27:14 +00:00
|
|
|
*/
|
|
|
|
m_CursorStartPos = screen->m_Curseur;
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Block_Enable && !(localbutt & GR_M_DCLICK) )
|
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
if( ( screen->m_BlockLocate.m_Command == BLOCK_IDLE )
|
2010-01-17 14:20:29 +00:00
|
|
|
|| ( screen->m_BlockLocate.m_State == STATE_NO_BLOCK ) )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
screen->m_BlockLocate.SetOrigin( m_CursorStartPos );
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
if( event.LeftDown() || event.MiddleDown() )
|
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
if( screen->m_BlockLocate.m_State == STATE_BLOCK_MOVE )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
2009-12-29 10:35:11 +00:00
|
|
|
m_AutoPAN_Request = false;
|
2007-08-22 05:11:01 +00:00
|
|
|
m_Parent->HandleBlockPlace( &DC );
|
2008-08-26 09:06:26 +00:00
|
|
|
s_IgnoreNextLeftButtonRelease = true;
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
else if( ( m_CanStartBlock >= 0 )
|
2010-01-17 14:20:29 +00:00
|
|
|
&& ( event.LeftIsDown() || event.MiddleIsDown() )
|
|
|
|
&& ManageCurseur == NULL
|
|
|
|
&& ForceCloseManageCurseur == NULL )
|
2009-11-23 15:16:50 +00:00
|
|
|
{
|
|
|
|
// Mouse is dragging: if no block in progress, start a block
|
|
|
|
// command.
|
2009-07-25 04:53:39 +00:00
|
|
|
if( screen->m_BlockLocate.m_State == STATE_NO_BLOCK )
|
2010-01-17 14:20:29 +00:00
|
|
|
{
|
|
|
|
// Start a block command
|
2007-08-22 05:11:01 +00:00
|
|
|
int cmd_type = kbstat;
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
if( event.MiddleIsDown() )
|
|
|
|
cmd_type |= MOUSE_MIDDLE;
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* A block command is started if the drag is enough. A small
|
|
|
|
* drag is ignored (it is certainly a little mouse move when
|
|
|
|
* clicking) not really a drag mouse
|
2008-01-18 20:27:14 +00:00
|
|
|
*/
|
|
|
|
if( MinDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND )
|
|
|
|
MinDragEventCount++;
|
2007-08-22 05:11:01 +00:00
|
|
|
else
|
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
if( !m_Parent->HandleBlockBegin( &DC, cmd_type,
|
|
|
|
m_CursorStartPos ) )
|
2008-01-18 20:27:14 +00:00
|
|
|
{
|
|
|
|
// should not occurs: error
|
|
|
|
m_Parent->DisplayToolMsg(
|
|
|
|
wxT( "WinEDA_DrawPanel::OnMouseEvent() Block Error" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_AutoPAN_Request = TRUE;
|
|
|
|
SetCursor( m_PanelCursor = wxCURSOR_SIZING );
|
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( event.ButtonUp( 1 ) || event.ButtonUp( 2 ) )
|
2007-12-09 09:00:15 +00:00
|
|
|
{
|
|
|
|
/* Release the mouse button: end of block.
|
2009-11-23 15:16:50 +00:00
|
|
|
* The command can finish (DELETE) or have a next command (MOVE,
|
|
|
|
* COPY). However the block command is canceled if the block
|
|
|
|
* size is small because a block command filtering is already
|
|
|
|
* made, this case happens, but only when the on grid cursor has
|
|
|
|
* not moved.
|
2007-08-22 05:11:01 +00:00
|
|
|
*/
|
2008-03-06 01:46:30 +00:00
|
|
|
#define BLOCK_MINSIZE_LIMIT 1
|
2007-08-22 05:11:01 +00:00
|
|
|
bool BlockIsSmall =
|
2009-11-23 15:16:50 +00:00
|
|
|
( ABS( screen->Scale( screen->m_BlockLocate.GetWidth() ) )
|
|
|
|
< BLOCK_MINSIZE_LIMIT)
|
2010-01-17 14:20:29 +00:00
|
|
|
&& ( ABS( screen->Scale( screen->m_BlockLocate.GetHeight() ) )
|
|
|
|
< BLOCK_MINSIZE_LIMIT);
|
2007-08-22 05:11:01 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
if( (screen->m_BlockLocate.m_State
|
|
|
|
!= STATE_NO_BLOCK) && BlockIsSmall )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
|
|
|
if( ForceCloseManageCurseur )
|
|
|
|
{
|
|
|
|
ForceCloseManageCurseur( this, &DC );
|
2009-12-29 10:35:11 +00:00
|
|
|
m_AutoPAN_Request = false;
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
SetCursor( m_PanelCursor = m_PanelDefaultCursor );
|
|
|
|
}
|
2009-07-25 04:53:39 +00:00
|
|
|
else if( screen->m_BlockLocate.m_State == STATE_BLOCK_END )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
2009-12-29 10:35:11 +00:00
|
|
|
m_AutoPAN_Request = false;
|
2007-08-22 05:11:01 +00:00
|
|
|
m_Parent->HandleBlockEnd( &DC );
|
|
|
|
SetCursor( m_PanelCursor = m_PanelDefaultCursor );
|
2009-07-25 04:53:39 +00:00
|
|
|
if( screen->m_BlockLocate.m_State == STATE_BLOCK_MOVE )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
|
|
|
m_AutoPAN_Request = TRUE;
|
|
|
|
SetCursor( m_PanelCursor = wxCURSOR_HAND );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-09 09:00:15 +00:00
|
|
|
// End of block command on a double click
|
2009-11-23 15:16:50 +00:00
|
|
|
// To avoid an unwanted block move command if the mouse is moved while
|
|
|
|
// double clicking
|
|
|
|
if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
if( screen->m_BlockLocate.m_Command != BLOCK_IDLE )
|
2007-08-22 05:11:01 +00:00
|
|
|
{
|
|
|
|
if( ForceCloseManageCurseur )
|
|
|
|
{
|
|
|
|
ForceCloseManageCurseur( this, &DC );
|
2009-12-29 10:35:11 +00:00
|
|
|
m_AutoPAN_Request = false;
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
2007-08-22 05:11:01 +00:00
|
|
|
wxString msg_debug;
|
|
|
|
msg_debug.Printf( " block state %d, cmd %d",
|
2009-11-23 15:16:50 +00:00
|
|
|
screen->m_BlockLocate.m_State,
|
|
|
|
screen->m_BlockLocate.m_Command );
|
2007-08-22 05:11:01 +00:00
|
|
|
m_Parent->PrintMsg( msg_debug );
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
LastPanel = this;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
void WinEDA_DrawPanel::OnKeyEvent( wxKeyEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-01-17 14:20:29 +00:00
|
|
|
long key, localkey;
|
|
|
|
bool escape = false;
|
2009-01-17 20:31:19 +00:00
|
|
|
wxPoint pos;
|
2007-08-22 05:11:01 +00:00
|
|
|
|
|
|
|
key = localkey = event.GetKeyCode();
|
|
|
|
|
|
|
|
switch( localkey )
|
|
|
|
{
|
|
|
|
case WXK_CONTROL:
|
|
|
|
case WXK_CAPITAL:
|
|
|
|
case WXK_SHIFT:
|
|
|
|
case WXK_NUMLOCK:
|
|
|
|
case WXK_LBUTTON:
|
|
|
|
case WXK_RBUTTON:
|
2007-09-27 09:08:47 +00:00
|
|
|
case WXK_ALT:
|
2007-08-22 05:11:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case WXK_ESCAPE:
|
|
|
|
escape = m_AbortRequest = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( event.ControlDown() )
|
|
|
|
localkey |= GR_KB_CTRL;
|
|
|
|
if( event.AltDown() )
|
|
|
|
localkey |= GR_KB_ALT;
|
|
|
|
if( event.ShiftDown() && (key > 256) )
|
|
|
|
localkey |= GR_KB_SHIFT;
|
|
|
|
|
2010-01-20 18:59:46 +00:00
|
|
|
/* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z
|
|
|
|
* They have an ascii code from 1 to 27 remapped
|
|
|
|
* GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z'
|
|
|
|
*/
|
|
|
|
if( (localkey & (GR_KB_CTRL|GR_KB_ALT|GR_KB_SHIFT)) == GR_KB_CTRL )
|
|
|
|
localkey += 'A' - 1;
|
|
|
|
|
2010-01-17 14:20:29 +00:00
|
|
|
INSTALL_DC( DC, this );
|
2009-12-19 16:10:25 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
BASE_SCREEN* Screen = GetScreen();
|
|
|
|
|
|
|
|
g_KeyPressed = localkey;
|
|
|
|
|
|
|
|
if( escape )
|
|
|
|
{
|
|
|
|
if( ManageCurseur && ForceCloseManageCurseur )
|
|
|
|
{
|
|
|
|
SetCursor( m_PanelCursor = m_PanelDefaultCursor );
|
|
|
|
ForceCloseManageCurseur( this, &DC );
|
|
|
|
SetCursor( m_PanelCursor = m_PanelDefaultCursor );
|
|
|
|
}
|
|
|
|
else
|
2007-08-15 02:43:57 +00:00
|
|
|
{
|
|
|
|
m_PanelCursor = m_PanelDefaultCursor = wxCURSOR_ARROW;
|
2007-08-22 05:11:01 +00:00
|
|
|
m_Parent->SetToolID( 0, m_PanelCursor, wxEmptyString );
|
2007-08-15 02:43:57 +00:00
|
|
|
}
|
2007-08-22 05:11:01 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-17 20:31:19 +00:00
|
|
|
/* Some key commands use the current mouse position: refresh it */
|
|
|
|
pos = CalcUnscrolledPosition( wxGetMousePosition() - GetScreenPosition() );
|
2007-12-09 09:00:15 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
/* Compute cursor position in screen units (pixel) including the
|
|
|
|
* current scroll bar position. Also known as device units to wxDC. */
|
2009-01-17 20:31:19 +00:00
|
|
|
Screen->m_MousePositionInPixels = pos;
|
2007-12-08 23:24:14 +00:00
|
|
|
|
2010-02-08 18:15:42 +00:00
|
|
|
/* Compute the cursor position in drawing units. Also known as logical units
|
|
|
|
* to wxDC. */
|
2009-01-17 20:31:19 +00:00
|
|
|
Screen->m_MousePosition = CursorRealPosition( pos );
|
2007-12-06 16:58:12 +00:00
|
|
|
|
2009-01-17 20:31:19 +00:00
|
|
|
m_Parent->GeneralControle( &DC, pos );
|
2007-06-26 10:42:11 +00:00
|
|
|
|
2007-08-22 05:11:01 +00:00
|
|
|
#if 0
|
|
|
|
event.Skip(); // Allow menu shortcut processing
|
2007-06-26 10:42:11 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2008-12-19 13:51:48 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2008-12-19 13:51:48 +00:00
|
|
|
void WinEDA_DrawPanel::OnPan( wxCommandEvent& event )
|
|
|
|
{
|
2010-01-17 14:20:29 +00:00
|
|
|
int x, y;
|
2010-02-22 16:45:35 +00:00
|
|
|
int ppux, ppuy;
|
|
|
|
int unitsX, unitsY;
|
|
|
|
int maxX, maxY;
|
2008-12-19 13:51:48 +00:00
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
GetViewStart( &x, &y );
|
|
|
|
GetScrollPixelsPerUnit( &ppux, &ppuy );
|
|
|
|
GetVirtualSize( &unitsX, &unitsY );
|
|
|
|
maxX = unitsX;
|
|
|
|
maxY = unitsY;
|
|
|
|
unitsX /= ppux;
|
|
|
|
unitsY /= ppuy;
|
2008-12-19 13:51:48 +00:00
|
|
|
|
|
|
|
switch( event.GetId() )
|
|
|
|
{
|
|
|
|
case ID_PAN_UP:
|
2010-02-08 18:15:42 +00:00
|
|
|
y -= m_scrollIncrementY;
|
2008-12-19 13:51:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_PAN_DOWN:
|
2010-02-08 18:15:42 +00:00
|
|
|
y += m_scrollIncrementY;
|
2008-12-19 13:51:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_PAN_LEFT:
|
2010-02-08 18:15:42 +00:00
|
|
|
x -= m_scrollIncrementX;
|
2008-12-19 13:51:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_PAN_RIGHT:
|
2010-02-08 18:15:42 +00:00
|
|
|
x += m_scrollIncrementX;
|
2008-12-19 13:51:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxLogDebug( wxT( "Unknown ID %d in WinEDA_DrawPanel::OnPan()." ),
|
2010-02-22 16:45:35 +00:00
|
|
|
event.GetId() );
|
2008-12-19 13:51:48 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 16:45:35 +00:00
|
|
|
if( x < 0 )
|
|
|
|
x = 0;
|
|
|
|
if( y < 0 )
|
|
|
|
y = 0;
|
|
|
|
if( x > maxX )
|
|
|
|
x = maxX;
|
|
|
|
if( y > maxY )
|
|
|
|
y = maxY;
|
|
|
|
|
2010-02-23 20:22:31 +00:00
|
|
|
Scroll( x/ppux, y/ppuy );
|
2008-12-19 13:51:48 +00:00
|
|
|
}
|
2009-09-14 13:24:17 +00:00
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
void WinEDA_DrawPanel::UnManageCursor( int id, int cursor,
|
|
|
|
const wxString& title )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
if( ManageCurseur && ForceCloseManageCurseur )
|
|
|
|
{
|
2009-12-20 19:48:58 +00:00
|
|
|
INSTALL_DC( dc, this );
|
2009-09-14 13:24:17 +00:00
|
|
|
ForceCloseManageCurseur( this, &dc );
|
|
|
|
m_AutoPAN_Request = false;
|
2009-12-20 19:48:58 +00:00
|
|
|
}
|
|
|
|
if( id != -1 && cursor != -1 )
|
|
|
|
{
|
|
|
|
wxASSERT( cursor > wxCURSOR_NONE && cursor < wxCURSOR_MAX );
|
|
|
|
m_Parent->SetToolID( id, cursor, title );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
}
|