Commit 34094e77 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Fix and enable optimized grid drawing and other minor changes.

* Fix optimized bitmap grid drawing method.
* Enable optimized grid drawing method on Windows and Linux.
* Create a helper class for resetting and restoring device context scale
  and origin settings for blitting purposes.
* Use wxLogTrace instead of wxLogDebug for coordinate dumping in
  drawpanel.cpp.  See comments for more information on enabling coordinate
  tracing.
* Add flag to allow hiding the drawing cross hair.  Hide cross hair by
  default on OSX.
* Move get cross hair device position code from draw panel object to base
  screen object.
* Remove redundant parent member variable from draw panel object by
  overriding wxWindow::GetParent() method.
parent 563bff9d
...@@ -423,6 +423,18 @@ wxPoint BASE_SCREEN::GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize ) ...@@ -423,6 +423,18 @@ wxPoint BASE_SCREEN::GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize )
} }
wxPoint BASE_SCREEN::GetCrossHairScreenPosition() const
{
wxPoint pos = m_Curseur - m_DrawOrg;
double scalar = GetScalingFactor();
pos.x = wxRound( (double) pos.x * scalar );
pos.y = wxRound( (double) pos.y * scalar );
return pos;
}
/* free the undo and the redo lists /* free the undo and the redo lists
*/ */
void BASE_SCREEN::ClearUndoRedoList() void BASE_SCREEN::ClearUndoRedoList()
......
...@@ -727,12 +727,12 @@ void EDA_DRAW_FRAME::LoadSettings() ...@@ -727,12 +727,12 @@ void EDA_DRAW_FRAME::LoadSettings()
bool btmp; bool btmp;
if ( cfg->Read( m_FrameName + ShowGridEntryKeyword, &btmp ) ) if ( cfg->Read( m_FrameName + ShowGridEntryKeyword, &btmp ) )
SetGridVisibility( btmp); SetGridVisibility( btmp );
int itmp; int itmp;
if( cfg->Read( m_FrameName + GridColorEntryKeyword, &itmp ) ) if( cfg->Read( m_FrameName + GridColorEntryKeyword, &itmp ) )
SetGridColor(itmp); SetGridColor( itmp );
cfg->Read( m_FrameName + LastGridSizeId, &m_LastGridSizeId, 0L ); cfg->Read( m_FrameName + LastGridSizeId, &m_LastGridSizeId, 0L );
} }
......
This diff is collapsed.
...@@ -198,7 +198,7 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& component_refere ...@@ -198,7 +198,7 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& component_refere
wxPoint old_cursor_position = sheet->LastScreen()->m_Curseur; wxPoint old_cursor_position = sheet->LastScreen()->m_Curseur;
sheet->LastScreen()->m_Curseur = pos; sheet->LastScreen()->m_Curseur = pos;
curpos = DrawPanel->CursorScreenPosition(); curpos = GetScreen()->GetCrossHairScreenPosition();
DrawPanel->GetViewStart( &( GetScreen()->m_StartVisu.x ), DrawPanel->GetViewStart( &( GetScreen()->m_StartVisu.x ),
&( GetScreen()->m_StartVisu.y ) ); &( GetScreen()->m_StartVisu.y ) );
......
...@@ -134,7 +134,9 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin ...@@ -134,7 +134,9 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin
layerBitmap = new wxBitmap( bitmapWidth, bitmapHeight ); layerBitmap = new wxBitmap( bitmapWidth, bitmapHeight );
screenBitmap = new wxBitmap( bitmapWidth, bitmapHeight ); screenBitmap = new wxBitmap( bitmapWidth, bitmapHeight );
layerDC.SelectObject( *layerBitmap ); layerDC.SelectObject( *layerBitmap );
EDA_Rect tmpRect = aPanel->m_ClipBox;
aPanel->DoPrepareDC( layerDC ); aPanel->DoPrepareDC( layerDC );
aPanel->m_ClipBox = tmpRect;
layerDC.SetBackground( bgBrush ); layerDC.SetBackground( bgBrush );
layerDC.SetBackgroundMode( wxSOLID ); layerDC.SetBackgroundMode( wxSOLID );
layerDC.Clear(); layerDC.Clear();
......
...@@ -244,7 +244,7 @@ public: ...@@ -244,7 +244,7 @@ public:
* @return the the current scale used to draw items on screen * @return the the current scale used to draw items on screen
* draw coordinates are user coordinates * GetScalingFactor( ) * draw coordinates are user coordinates * GetScalingFactor( )
*/ */
double GetScalingFactor() double GetScalingFactor() const
{ {
return (double) m_ZoomScalar / (double) GetZoom(); return (double) m_ZoomScalar / (double) GetZoom();
} }
...@@ -365,6 +365,13 @@ public: ...@@ -365,6 +365,13 @@ public:
*/ */
wxPoint GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize = NULL ); wxPoint GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize = NULL );
/**
* Function GetCursorScreenPosition
* returns the cross hair position in device (display) units.b
* @return The current cross hair position.
*/
wxPoint GetCrossHairScreenPosition() const;
/** /**
* Function GetNearestGridPosition * Function GetNearestGridPosition
* returns the nearest \a aGridSize location to \a aPosition. * returns the nearest \a aGridSize location to \a aPosition.
......
...@@ -18,50 +18,39 @@ class PCB_SCREEN; ...@@ -18,50 +18,39 @@ class PCB_SCREEN;
class EDA_DRAW_PANEL : public wxScrolledWindow class EDA_DRAW_PANEL : public wxScrolledWindow
{ {
private: private:
EDA_DRAW_FRAME* m_Parent;
int m_cursor; ///< Current mouse cursor shape id. int m_cursor; ///< Current mouse cursor shape id.
int m_defaultCursor; ///< The default mouse cursor shape id. int m_defaultCursor; ///< The default mouse cursor shape id.
bool m_showCrossHair; ///< Indicate if cross hair is to be shown.
int m_cursorLevel; // Index for cursor redraw in XOR mode.
public: public:
EDA_Rect m_ClipBox; // the clipbox used in screen EDA_Rect m_ClipBox; // the clipbox used in screen redraw (usually gives the
// redraw (usually gives the
// visible area in internal units) // visible area in internal units)
wxPoint m_CursorStartPos; // useful in testing the cursor wxPoint m_CursorStartPos; // useful in testing the cursor movement
// movement
int m_scrollIncrementX; // X axis scroll increment in pixels per unit. int m_scrollIncrementX; // X axis scroll increment in pixels per unit.
int m_scrollIncrementY; // Y axis scroll increment in pixels per unit. int m_scrollIncrementY; // Y axis scroll increment in pixels per unit.
bool m_AbortRequest; // Flag to abort long commands bool m_AbortRequest; // Flag to abort long commands
bool m_AbortEnable; // TRUE if abort button or menu to bool m_AbortEnable; // TRUE if abort button or menu to be displayed
// be displayed
bool m_AutoPAN_Enable; // TRUE to allow auto pan bool m_AutoPAN_Enable; // TRUE to allow auto pan
bool m_AutoPAN_Request; // TRUE to request an auto pan bool m_AutoPAN_Request; // TRUE to request an auto pan (will be made only if
// (will be made only if
// m_AutoPAN_Enable = true) // m_AutoPAN_Enable = true)
int m_IgnoreMouseEvents; // when non-zero (true), then ignore mouse events
int m_IgnoreMouseEvents; // when non-zero (true), then
// ignore mouse events
bool m_Block_Enable; // TRUE to accept Block Commands bool m_Block_Enable; // TRUE to accept Block Commands
// useful to avoid false start block in certain cases // useful to avoid false start block in certain cases
// (like switch from a sheet to an other sheet // (like switch from a sheet to an other sheet
int m_CanStartBlock; // >= 0 (or >= n) if a block can int m_CanStartBlock; // >= 0 (or >= n) if a block can start
// start bool m_PrintIsMirrored; // True when drawing in mirror mode. Used in draw arc function,
bool m_PrintIsMirrored; // True when drawing in mirror // because arcs are oriented, and in mirror mode, orientations
// mode. Used in draw arc function, // are reversed
// because arcs are oriented, and
// in mirror mode, orientations are
// reversed
int m_CursorLevel; // Index for cursor redraw in XOR
// mode
#ifdef USE_WX_OVERLAY #ifdef USE_WX_OVERLAY
// MAC Uses overlay to workaround the wxINVERT and wxXOR miss // MAC Uses overlay to workaround the wxINVERT and wxXOR miss
wxOverlay m_overlay; wxOverlay m_overlay;
#endif #endif
/* Cursor management (used in editing functions) */ /* Cursor management (used in editing functions) */
/* Mouse capture move callback function prototype. */ /* Mouse capture move callback function prototype. */
...@@ -78,10 +67,7 @@ public: ...@@ -78,10 +67,7 @@ public:
BASE_SCREEN* GetScreen(); BASE_SCREEN* GetScreen();
EDA_DRAW_FRAME* GetParent() virtual EDA_DRAW_FRAME* GetParent();
{
return m_Parent;
}
void OnPaint( wxPaintEvent& event ); void OnPaint( wxPaintEvent& event );
...@@ -97,10 +83,11 @@ public: ...@@ -97,10 +83,11 @@ public:
/** /**
* Function DrawGrid * Function DrawGrid
* @param DC = current Device Context * draws a grid to \a aDC.
* draws the grid * @see m_ClipBox to determine the damaged area of the drawing to draw the grid.
* - the grid is drawn only if the zoom level allows a good visibility * @see EDA_DRAW_FRAME::IsGridVisible() to determine if grid is shown.
* - the grid is always centered on the screen center * @see EDA_DRAW_FRAME::GetGridColor() for the color of the grid.
* @param aDC The device context to draw the grid.
*/ */
void DrawGrid( wxDC* DC ); void DrawGrid( wxDC* DC );
...@@ -124,25 +111,32 @@ public: ...@@ -124,25 +111,32 @@ public:
void OnEraseBackground( wxEraseEvent& event ) { } void OnEraseBackground( wxEraseEvent& event ) { }
/**
* Function OnActivate
* handles window activation events.
* <p>
* The member m_CanStartBlock is initialize to avoid a block start command 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.
*</p>
*/
void OnActivate( wxActivateEvent& event ); void OnActivate( wxActivateEvent& event );
/** /**
* Prepare the device context for drawing. * Fucntion DoPrepareDC
* * sets up the device context \a aDC for drawing.
* This overrides wxScrolledWindow::DoPrepareDC() for drawing depending * <p>
* on the render mode selected a build time. If the old kicad coordinate * This overrides wxScrolledWindow::DoPrepareDC() for settting up the the device context
* scaling code is used then this code doesn't do any thing other than * used for drawing. The scale factor and drawing logical offset are set and the base
* update the boundary box. If wxDC coordinate manipulation is used, then * method is called to set the DC device origin (scroll bar position). This connects
* the scale factor and drawing logical offset is set. Then the base * everything together to achieve the appropriate coordinate manipulation using wxDC
* method is called to set the DC device origin and user scale. This * LogicalToDeviceXXX and DeviceToLogixalXXX methods. This gets called automatically
* connects everything together to achieve the appropriate coordinate * for a paint event. If you do any drawing outside the paint event, you must call
* manipulation using wxDC LogicalToDeviceXXX and DeviceToLogixalXXX * DoPrepareDC manually.
* methods. This gets called automatically for a paint event. If you do * </p>
* any drawing outside the paint event, you must call DoPrepareDC manually. * @param aDC The device context to prepare.
*
* @param dc - The device context to prepare.
*/ */
virtual void DoPrepareDC(wxDC& dc); virtual void DoPrepareDC( wxDC& aDC );
/** /**
* Function DeviceToLogical * Function DeviceToLogical
...@@ -157,6 +151,16 @@ public: ...@@ -157,6 +151,16 @@ public:
wxRect DeviceToLogical( const wxRect& aRect, wxDC& aDC ); wxRect DeviceToLogical( const wxRect& aRect, wxDC& aDC );
/* Mouse and keys events */ /* Mouse and keys events */
/**
* Funtion OnMouseWheel
* handles mouse wheel events.
* <p>
* The mouse wheel is used to provide support for zooming and panning. This
* is accomplished by converting mouse wheel events in pseudo menu command
* events and sending them to the appropriate parent window event handler.
*</p>
*/
void OnMouseWheel( wxMouseEvent& event ); void OnMouseWheel( wxMouseEvent& event );
void OnMouseEvent( wxMouseEvent& event ); void OnMouseEvent( wxMouseEvent& event );
void OnMouseLeaving( wxMouseEvent& event ); void OnMouseLeaving( wxMouseEvent& event );
...@@ -173,10 +177,20 @@ public: ...@@ -173,10 +177,20 @@ public:
void SetGrid( const wxRealPoint& size ); void SetGrid( const wxRealPoint& size );
wxRealPoint GetGrid(); wxRealPoint GetGrid();
/**
* Function OnRightClick
* builds and displays a context menu on a right mouse button click.
* @return true if the context menu is shown, or false
*/
bool OnRightClick( wxMouseEvent& event ); bool OnRightClick( wxMouseEvent& event );
void Process_Special_Functions( wxCommandEvent& event );
bool IsPointOnDisplay( wxPoint ref_pos ); /**
* Function IsPointOnDisplay
* @param aPosition The position to test in logical (drawing) units.
* @return true if \a aPosition is visible on the screen.
* false if \a aPosition is not visiable on the screen.
*/
bool IsPointOnDisplay( const wxPoint& aPosition );
/** /**
* Function SetClipBox * Function SetClipBox
...@@ -198,19 +212,6 @@ public: ...@@ -198,19 +212,6 @@ public:
void ReDraw( wxDC* DC, bool erasebg = TRUE ); void ReDraw( wxDC* DC, bool erasebg = TRUE );
/**
* Function CursorRealPosition
* @return the position in user units of location ScreenPos
* @param aPosition = the screen (in pixel) position to convert
*/
wxPoint CursorRealPosition( const wxPoint& aPosition );
/**
* Function CursorScreenPosition
* @return the cursor current position in pixels in the screen draw area
*/
wxPoint CursorScreenPosition();
/** /**
* Function RefreshDrawingRect * Function RefreshDrawingRect
* redraws the contents of \a aRect in drawing units. \a aRect is converted to * redraws the contents of \a aRect in drawing units. \a aRect is converted to
...@@ -241,7 +242,7 @@ public: ...@@ -241,7 +242,7 @@ public:
* *
* The user cursor is not the mouse cursor although they may be at the * The user cursor is not the mouse cursor although they may be at the
* same screen position. The mouse cursor is still render by the OS. * same screen position. The mouse cursor is still render by the OS.
* This is a drawn cursor that is used to snap to grid when grid snapping * This is a drawn cross hair that is used to snap to grid when grid snapping
* is enabled. This is required because OSX does not allow moving the * is enabled. This is required because OSX does not allow moving the
* cursor programmatically. * cursor programmatically.
* *
...@@ -266,8 +267,7 @@ public: ...@@ -266,8 +267,7 @@ public:
* @param aTitle The tool message to display in the status bar or wxEmptyString to clear * @param aTitle The tool message to display in the status bar or wxEmptyString to clear
* the message. * the message.
*/ */
void UnManageCursor( int aId = -1, int aCursorId = -1, void UnManageCursor( int aId = -1, int aCursorId = -1, const wxString& aTitle = wxEmptyString );
const wxString& aTitle = wxEmptyString );
int GetDefaultCursor() const { return m_defaultCursor; } int GetDefaultCursor() const { return m_defaultCursor; }
......
...@@ -86,6 +86,55 @@ private: ...@@ -86,6 +86,55 @@ private:
}; };
/**
* Class EDA_BLIT_NORMALIZER
* is a helper class for clearing a device context scale and offset parameters before
* performing a Blit operation.
* <p>
* This class keeps a temporary copy of the scale and offset parameters of a device
* context and then restores them when it goes out of scope.
* </p>
*/
class EDA_BLIT_NORMALIZER
{
public:
EDA_BLIT_NORMALIZER( wxDC* aDC )
: m_dc( aDC )
{
if( aDC )
{
aDC->GetUserScale( &m_userScaleX, &m_userScaleY );
aDC->GetLogicalOrigin( &m_logicalOriginX, &m_logicalOriginY );
aDC->GetDeviceOrigin( &m_deviceOriginX, &m_deviceOriginY );
aDC->SetUserScale( 1.0, 1.0 );
aDC->SetLogicalOrigin( 0, 0 );
aDC->SetDeviceOrigin( 0, 0 );
}
}
~EDA_BLIT_NORMALIZER()
{
if( m_dc )
{
m_dc->SetUserScale( m_userScaleX, m_userScaleY );
m_dc->SetLogicalOrigin( m_logicalOriginX, m_logicalOriginY );
m_dc->SetDeviceOrigin( m_deviceOriginX, m_deviceOriginY );
}
}
private:
wxDC* m_dc;
double m_userScaleX;
double m_userScaleY;
int m_logicalOriginX;
int m_logicalOriginY;
int m_deviceOriginX;
int m_deviceOriginY;
DECLARE_NO_COPY_CLASS( EDA_BLIT_NORMALIZER )
};
#if USE_WX_GRAPHICS_CONTEXT #if USE_WX_GRAPHICS_CONTEXT
#include <wx/dcgraph.h> #include <wx/dcgraph.h>
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment