56 const wxPoint& aPosition,
const wxSize& aSize,
58 wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ),
59 m_edaFrame( nullptr ),
63 m_viewControls( nullptr ),
64 m_backend( GAL_TYPE_NONE ),
65 m_options( aOptions ),
66 m_eventDispatcher( nullptr ),
74 SetLayoutDirection( wxLayout_LeftToRight );
81 wxWindow* ancestor = aParentWindow->GetParent();
83 while( ancestor && !dynamic_cast<EDA_DRAW_FRAME*>( ancestor ) )
84 ancestor = ancestor->GetParent();
87 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( ancestor );
91 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
93 ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
94 EnableScrolling(
false,
false );
102 const wxEventType events[] = {
120 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) 126 for( wxEventType eventType : events )
161 wxScrolledCanvas::SetFocus();
201 static_cast<KIGFX::RENDER_SETTINGS*>(
m_painter->GetSettings() );
242 catch( std::exception& err )
249 _(
"Could not use OpenGL, falling back to software rendering" ),
250 wxString( err.what() ) );
260 totalRealTime.
Stop();
261 wxLogTrace(
"GAL_PROFILE",
"EDA_DRAW_PANEL_GAL::DoRePaint(): %.1f ms", totalRealTime.
msecs() );
276 wxSize clientSize = GetClientSize();
282 clientSize.x = std::max( 10, clientSize.x );
283 clientSize.y = std::max( 10, clientSize.y );
294 if( infobar && infobar->
IsLocked() )
305 wxLongLong t = wxGetLocalTimeMillis();
335 const wxEventType eventTypes[] = { wxEVT_TOOL };
339 for( wxEventType type : eventTypes )
347 for( wxEventType type : eventTypes )
420 if( errormsg.empty() )
431 _(
"Could not use OpenGL, falling back to software rendering" ),
458 catch( std::runtime_error& err )
470 wxWindow* galWindow = dynamic_cast<wxWindow*>( new_gal );
474 galWindow->Connect( wxEVT_SET_CURSOR,
482 wxSize clientSize = GetClientSize();
483 clientSize.x = std::max( 10, clientSize.x );
484 clientSize.y = std::max( 10, clientSize.y );
487 if( grid_size.
x > 0 && grid_size.
y > 0 )
513 #if defined( _WIN32 ) 516 shouldSetFocus = shouldSetFocus && (
m_edaFrame->GetHWND() == GetForegroundWindow() );
533 bool shouldSetFocus =
536 #if defined( _WIN32 ) 539 shouldSetFocus = shouldSetFocus && (
m_edaFrame->GetHWND() == GetForegroundWindow() );
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
bool m_pendingRefresh
Is there a redraw event requested?
wxTimer m_refreshTimer
Timer to prevent too-frequent refreshing.
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
void SetClearColor(const COLOR4D &aColor)
virtual void SetHighContrastLayer(int aLayer)
Take care of display settings for the given layer to be displayed in high contrast mode.
void ForceRefresh()
Force a redraw.
virtual const COLOR4D & GetGridColor()=0
Return current grid color settings.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
bool IsModalDialogFocused()
void ReverseDrawOrder(bool aFlag)
Only takes effect if UseDrawPriority is true.
GAL_TYPE m_backend
Currently used GAL.
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.
KICURSOR m_currentKiCursor
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
static const wxEventType EVT_REFRESH_MOUSE
This file is part of the common library.
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
virtual const COLOR4D & GetCursorColor()=0
Return current cursor color settings.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
virtual const COLOR4D & GetBackgroundColor()=0
Return current background color settings.
double msecs(bool aSinceLast=false)
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
KIGFX::GAL_DISPLAY_OPTIONS & m_options
virtual void OnShow()
Called when the window is shown for the first time.
OpenGL implementation of the Graphics Abstraction Layer.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
static constexpr GAL_TYPE GAL_FALLBACK
void onLostFocus(wxFocusEvent &aEvent)
virtual bool HasTarget(RENDER_TARGET aTarget)
Return true if the target exists.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
void DoRePaint()
Repaint the canvas, and fix scrollbar cursors.
void onShowTimer(wxTimerEvent &aEvent)
A small class to help profiling.
void ClearDebugOverlay()
Clear the contents of the debug overlay and removes it from the VIEW.
void SetCurrentCursor(KICURSOR cursor)
Set the current cursor shape for this panel.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
void onEnter(wxMouseEvent &aEvent)
WX_VIEW_CONTROLS class definition.
bool IsInputControlFocused()
Checks if a input control has focus.
Auxiliary rendering target (noncached)
This file contains miscellaneous commonly used macros and functions.
void onRefreshTimer(wxTimerEvent &aEvent)
void UpdateScrollbars()
End any mouse drag action still in progress.
bool m_drawing
True if GAL is currently redrawing the view.
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
bool IsLocked()
Returns true if the infobar is being updated.
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
wxWindow * m_parent
Pointer to the parent window.
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent))
VECTOR2< double > VECTOR2D
virtual void Redraw()
Immediately redraws the whole view.
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
bool IsTargetDirty(int aTarget) const
Return true if any of layers belonging to the target or the target itself should be redrawn.
GAL not used (the legacy wxDC engine is used)
static const int MinRefreshPeriod
60 FPS.
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
static const wxCursor GetCursor(KICURSOR aCursorType)
virtual void SetTopLayer(int aLayer)
Move the selected layer to the top, so it is displayed above all others.
virtual void DrawCursor(const VECTOR2D &aCursorPosition)
Draw the cursor.
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.
Items that may change while the view stays the same (noncached)
bool m_lostFocus
Flag to indicate that focus should be regained on the next mouse event.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
virtual void SetFocus() override
void SetLayerIsHighContrast(int aLayerId, bool aEnabled=true)
Set the specified layer as high-contrast.
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
void onSetCursor(wxSetCursorEvent &event)
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
void SetCursorColor(const COLOR4D &aCursorColor)
Set the cursor color.
virtual void ResizeScreen(int aWidth, int aHeight)
Resize the canvas.
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
void onSize(wxSizeEvent &aEvent)
void StartDrawing()
Begin drawing if it was stopped previously.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
const VECTOR2D & GetGridSize() const
Return the grid size.
virtual void ClearScreen()
Clear the screen.
TOOL_DISPATCHER * m_eventDispatcher
Processes and forwards events to tools.
A modified version of the wxInfoBar class that allows us to:
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
wxTimer m_onShowTimer
Timer used to execute OnShow() when the window finally appears on the screen.
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_debugOverlay
Optional overlay for drawing transient debug objects.
Main rendering target (cached)
static wxString CheckFeatures(GAL_DISPLAY_OPTIONS &aOptions)
Checks OpenGL features.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
bool m_drawingEnabled
Flag that determines if VIEW may use GAL for redrawing the screen.
VECTOR2D GetCursorPosition(bool aSnappingEnabled) const override
<
virtual bool IsVisible() const
Return true if the GAL canvas is visible on the screen.
void ClearTargets()
Clear targets that are marked as dirty.
void ClearHighContrastLayers()
Clear the list of active layers.
void SetGridVisibility(bool aVisibility)
Set the visibility setting of the grid.
wxLongLong m_lastRefresh
Last timestamp when the panel was refreshed.
WX_INFOBAR * GetInfoBar()
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
VECTOR2D m_ScrollCenter
Current scroll center point in logical units.
bool IsDialogPreview() const
bool GetGridVisibility() const
wxCursor m_currentCursor
Current mouse cursor shape id.
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
bool m_stealsFocus
Flag to indicate whether the panel should take focus at certain times (when moused over,...
BASE_SCREEN class implementation.
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
std::shared_ptr< KIGFX::VIEW_OVERLAY > DebugOverlay()
Create an overlay for rendering debug graphics.
virtual bool IsContextLocked()
Checks the state of the context lock.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual bool IsInitialized() const
Return the initialization status for the canvas.
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
void MarkDirty()
Force redraw of view on the next rendering.
bool IsDirty() const
Return true if any of the VIEW layers needs to be refreshened.
Abstract interface for drawing on a 2D-surface.