57 const wxPoint& aPosition,
const wxSize& aSize,
59 wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ),
60 m_edaFrame( nullptr ),
64 m_viewControls( nullptr ),
65 m_backend( GAL_TYPE_NONE ),
66 m_options( aOptions ),
67 m_eventDispatcher( nullptr ),
76 SetLayoutDirection( wxLayout_LeftToRight );
83 wxWindow* ancestor = aParentWindow->GetParent();
85 while( ancestor && !dynamic_cast<EDA_DRAW_FRAME*>( ancestor ) )
86 ancestor = ancestor->GetParent();
89 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( ancestor );
93 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
95 ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
96 EnableScrolling(
false,
false );
105 const wxEventType events[] = {
123 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) 129 for( wxEventType eventType : events )
164 wxScrolledCanvas::SetFocus();
196 ( *m_PaintEventCounter )++;
202 static_cast<KIGFX::RENDER_SETTINGS*>(
m_painter->GetSettings() );
207 PROF_TIMER cntCtxDestroy(
"view-context-destroy");
210 bool isDirty =
false;
221 catch( std::out_of_range& err )
226 msg.Printf( wxT(
"Out of Range error: %s" ), err.what() );
274 cntCtxDestroy.
Start();
276 catch( std::exception& err )
283 _(
"Could not use OpenGL, falling back to software rendering" ),
284 wxString( err.what() ) );
294 cntCtxDestroy.
Stop();
320 wxSize clientSize = GetClientSize();
326 clientSize.x = std::max( 10, clientSize.x );
327 clientSize.y = std::max( 10, clientSize.y );
338 if( infobar && infobar->
IsLocked() )
349 wxLongLong t = wxGetLocalTimeMillis();
443 if( errormsg.empty() )
454 _(
"Could not use OpenGL, falling back to software rendering" ),
481 catch( std::runtime_error& err )
496 wxSize clientSize = GetClientSize();
497 clientSize.x = std::max( 10, clientSize.x );
498 clientSize.y = std::max( 10, clientSize.y );
501 if( grid_size.
x > 0 && grid_size.
y > 0 )
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
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.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
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.
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.
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 ...
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
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)
void ClearDebugOverlay()
Clear the contents of the debug overlay and removes it from the VIEW.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
void onEnter(wxMouseEvent &aEvent)
WX_VIEW_CONTROLS class definition.
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.
bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
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.
virtual void SetTopLayer(int aLayer)
Move the selected layer to the top, so it is displayed above all others.
std::unique_ptr< PROF_COUNTER > m_PaintEventCounter
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.
wxLogTrace helper definitions.
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.
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.
A small class to help profiling.
void onSize(wxSizeEvent &aEvent)
void StartDrawing()
Begin drawing if it was stopped previously.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
virtual bool SetNativeCursorStyle(KICURSOR aCursor)
Set the cursor in the native panel.
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.
bool m_MouseCapturedLost
used on wxMSW: true after a wxEVT_MOUSE_CAPTURE_LOST was received false after the mouse is recaptured...
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.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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
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.
void Start()
Start or restart the counter.
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.