68 const wxPoint& aPosition,
const wxSize& aSize,
70 wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ),
71 m_MouseCapturedLost( false ),
72 m_parent( aParentWindow ),
73 m_edaFrame( nullptr ),
74 m_lastRepaintStart( 0 ),
75 m_lastRepaintEnd( 0 ),
77 m_drawingEnabled( false ),
78 m_needIdleRefresh( false ),
82 m_viewControls( nullptr ),
83 m_backend( GAL_TYPE_NONE ),
84 m_options( aOptions ),
85 m_eventDispatcher( nullptr ),
87 m_stealsFocus( true ),
88 m_statusPopup( nullptr )
92 if(
Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
93 ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
95 ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
97 SetLayoutDirection( wxLayout_LeftToRight );
104 wxWindow* ancestor = aParentWindow->GetParent();
107 ancestor = ancestor->GetParent();
114 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
116 EnableScrolling(
false,
false );
126 const wxEventType events[] = {
154 for( wxEventType eventType : events )
186 wxScrolledCanvas::SetFocus();
202 std::lock_guard<std::mutex> lock(
m_refreshMutex, std::adopt_lock );
224 if(
Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
229 ( *m_PaintEventCounter )++;
239 PROF_TIMER cntCtxDestroy(
"view-context-destroy");
242 bool isDirty =
false;
254 catch( std::out_of_range& err )
258 wxLogTrace(
traceDrawPanel, wxS(
"Out of Range error: %s" ), err.what() );
308 cntCtxDestroy.
Start();
312 cntCtxDestroy.
Stop();
314 catch( std::exception& err )
321 _(
"Could not use OpenGL, falling back to software rendering" ),
322 wxString( err.what() ) );
359 wxSize clientSize = GetClientSize();
366 clientSize.x = std::max( 10, clientSize.x + 1 );
367 clientSize.y = std::max( 10, clientSize.y + 1 );
378 if( infobar && infobar->
IsLocked() )
380 VECTOR2D halfScreen( std::ceil( 0.5 * clientSize.x ), std::ceil( 0.5 * clientSize.y ) );
497 if( errormsg.empty() )
508 _(
"Could not use OpenGL, falling back to software rendering" ),
535 catch( std::runtime_error& err )
550 wxSize clientSize = GetClientSize();
551 clientSize.x = std::max( 10, clientSize.x );
552 clientSize.y = std::max( 10, clientSize.y );
555 if( grid_size.
x > 0 && grid_size.
y > 0 )
598 timeLimit = std::clamp( timeLimit, 3LL, 150LL );
600 if( endDelta > timeLimit )
BASE_SCREEN class implementation.
VECTOR2D m_ScrollCenter
Current scroll center point in logical units.
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetContentScaleFactor() const override
Get the content scale factor, which may be different from the scale factor on some platforms.
WX_INFOBAR * GetInfoBar()
The base class for create windows for drawing purpose.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
std::unique_ptr< PROF_COUNTER > m_PaintEventCounter
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
void onLostFocus(wxFocusEvent &aEvent)
static constexpr GAL_TYPE GAL_FALLBACK
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
void onSize(wxSizeEvent &aEvent)
bool m_needIdleRefresh
True when canvas needs to be refreshed from idle handler.
bool IsDialogPreview() const
virtual void SetHighContrastLayer(int aLayer)
Take care of display settings for the given layer to be displayed in high contrast mode.
bool m_stealsFocus
Flag to indicate whether the panel should take focus at certain times (when moused over,...
KIGFX::GAL_DISPLAY_OPTIONS & m_options
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
static KIGFX::VC_SETTINGS GetVcSettings()
Gets a populated View Controls settings object dervived from our program settings.
virtual void SetTopLayer(int aLayer)
Move the selected layer to the top, so it is displayed above all others.
void ClearDebugOverlay()
Clear the contents of the debug overlay and removes it from the VIEW.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
void ForceRefresh()
Force a redraw.
bool m_drawing
True if GAL is currently redrawing the view.
void onShowTimer(wxTimerEvent &aEvent)
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
EDA_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
Create a drawing panel that is contained inside aParentWindow.
void onRefreshTimer(wxTimerEvent &aEvent)
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent))
bool m_lostFocus
Flag to indicate that focus should be regained on the next mouse event.
virtual void OnShow()
Called when the window is shown for the first time.
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_debugOverlay
Optional overlay for drawing transient debug objects.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
wxTimer m_refreshTimer
Timer to prevent too-frequent refreshing.
TOOL_DISPATCHER * m_eventDispatcher
Processes and forwards events to tools.
wxWindow * m_parent
Pointer to the parent window.
wxLongLong m_lastRepaintStart
Timestamp of the last repaint start.
@ GAL_TYPE_OPENGL
OpenGL implementation.
@ GAL_TYPE_CAIRO
Cairo implementation.
@ GAL_TYPE_NONE
GAL not used (the legacy wxDC engine is used)
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
void onIdle(wxIdleEvent &aEvent)
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void onEnter(wxMouseEvent &aEvent)
void RequestRefresh()
Make sure a refresh gets done on the next idle event if it hasn't already.
std::mutex m_refreshMutex
Blocks multiple calls to the draw.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
void StartDrawing()
Begin drawing if it was stopped previously.
wxLongLong m_lastRepaintEnd
Timestamp of the last repaint end.
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
bool m_drawingEnabled
Flag that determines if VIEW may use GAL for redrawing the screen.
std::shared_ptr< KIGFX::VIEW_OVERLAY > DebugOverlay()
Create an overlay for rendering debug graphics.
bool DoRePaint()
Repaint the canvas, and fix scrollbar cursors.
GAL_TYPE m_backend
Currently used GAL.
wxTimer m_onShowTimer
Timer used to execute OnShow() when the window finally appears on the screen.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
Abstract interface for drawing on a 2D-surface.
virtual void ResizeScreen(int aWidth, int aHeight)
Resize the canvas.
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
virtual bool SetNativeCursorStyle(KICURSOR aCursor, bool aHiDPI)
Set the cursor in the native panel.
virtual bool HasTarget(RENDER_TARGET aTarget)
Return true if the target exists.
void SetCursorColor(const COLOR4D &aCursorColor)
Set the cursor color.
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
const VECTOR2D & GetGridSize() const
Return the grid size.
virtual bool IsContextLocked()
Checks the state of the context lock.
bool GetGridVisibility() const
virtual void ClearScreen()
Clear the screen.
void SetClearColor(const COLOR4D &aColor)
virtual bool IsInitialized() const
Return the initialization status for the canvas.
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
void SetGridVisibility(bool aVisibility)
Set the visibility setting of the grid.
virtual void DrawCursor(const VECTOR2D &aCursorPosition)
Draw the cursor.
virtual bool IsVisible() const
Return true if the GAL canvas is visible on the screen.
OpenGL implementation of the Graphics Abstraction Layer.
static wxString CheckFeatures(GAL_DISPLAY_OPTIONS &aOptions)
Checks OpenGL features.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void ClearHighContrastLayers()
Clear the list of active layers.
virtual const COLOR4D & GetGridColor()=0
Return current grid color settings.
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
void SetLayerIsHighContrast(int aLayerId, bool aEnabled=true)
Set the specified layer as high-contrast.
virtual const COLOR4D & GetCursorColor()=0
Return current cursor color settings.
void ReverseDrawOrder(bool aFlag)
Only takes effect if UseDrawPriority is true.
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
void ClearTargets()
Clear targets that are marked as dirty.
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
virtual void Redraw()
Immediately redraws the whole view.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
bool IsTargetDirty(int aTarget) const
Return true if any of layers belonging to the target or the target itself should be redrawn.
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
bool IsDirty() const
Return true if any of the VIEW layers needs to be refreshened.
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Set given layer to be displayed on the top or sets back the default order of layers.
void MarkDirty()
Force redraw of view on the next rendering.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
VECTOR2D GetCursorPosition(bool aSnappingEnabled) const override
<
void UpdateScrollbars()
End any mouse drag action still in progress.
static const wxEventType EVT_REFRESH_MOUSE
virtual COMMON_SETTINGS * GetCommonSettings() const
A small class to help profiling.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
void Start()
Start or restart the counter.
RAII class that sets an value at construction and resets it to the original value at destruction.
A modified version of the wxInfoBar class that allows us to:
bool IsLocked()
Returns true if the infobar is being updated.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static const wxChar traceDrawPanel[]
Flag to enable drawing panel debugging output.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
@ TARGET_CACHED
Main rendering target (cached)
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
KICOMMON_API bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
KICOMMON_API bool IsModalDialogFocused()
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PGM_BASE & Pgm()
The global Program "get" accessor.
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
MOUSE_DRAG_ACTION m_dragLeft
bool m_horizontalPan
Enable the accelerating zoom controller.
bool m_autoPanSettingEnabled
Distance from cursor to VIEW edge when panning is active.
bool m_focusFollowSchPcb
Flag for turning on autopanning.
float m_autoPanAcceleration
If the cursor is allowed to be warped.
MOUSE_DRAG_ACTION m_dragMiddle
int m_zoomSpeed
When true, ignore zoom_speed and pick a platform-specific default.
int m_scrollModifierZoom
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
int m_scrollModifierPanH
What modifier key to enable vertical with the (vertical) scroll wheel.
bool m_warpCursor
Enable horizontal panning with the horizontal scroll/trackpad input.
MOUSE_DRAG_ACTION m_dragRight
Is last cursor motion event coming from keyboard arrow cursor motion action.
bool m_scrollReverseZoom
Whether to invert the scroll wheel movement for horizontal pan.
bool m_zoomAcceleration
Zoom speed for the non-accelerating zoom controller.
bool m_zoomSpeedAuto
What modifier key to enable zoom with the (vertical) scroll wheel.
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
VECTOR2< double > VECTOR2D
VECTOR2I ToVECTOR2I(const wxSize &aSize)
WX_VIEW_CONTROLS class definition.