KiCad PCB EDA Suite
Loading...
Searching...
No Matches
class_draw_panel_gal.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2013-2018 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 * @author Maciej Suminski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef PANELGAL_WXSTRUCT_H
25#define PANELGAL_WXSTRUCT_H
26
27#include <wx/window.h>
28#include <wx/timer.h>
29#include <wx/grid.h> // needed for MSVC to see wxScrolledCanvas indirectly exported
30#include <math/box2.h>
31#include <math/vector2d.h>
32#include <widgets/msgpanel.h>
33#include <memory>
34#include <mutex>
35#include <chrono>
36
37#include <gal/cursors.h>
38
39class BOARD;
40class EDA_DRAW_FRAME;
41class TOOL_DISPATCHER;
42class PROF_COUNTER;
43class wxImage;
44
45namespace KIPLATFORM
46{
47namespace UI
48{
50}
51}
52
53namespace KIGFX
54{
55class GAL;
56class VIEW;
57class WX_VIEW_CONTROLS;
58class VIEW_CONTROLS;
59class PAINTER;
60class GAL_DISPLAY_OPTIONS;
61class VIEW_OVERLAY;
62struct VC_SETTINGS;
63}
64
65
66class EDA_DRAW_PANEL_GAL : public wxScrolledCanvas
67{
68public:
76
77#ifdef __WXMAC__
78 // Cairo doesn't work on OSX so we really have no fallback available.
79 static constexpr GAL_TYPE GAL_FALLBACK = GAL_TYPE_OPENGL;
80#else
82#endif
84
93 EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
94 const wxPoint& aPosition, const wxSize& aSize,
96 GAL_TYPE aGalType = GAL_TYPE_OPENGL );
98
99 void SetFocus() override;
100
102 {
103 return m_statusPopup && m_statusPopup->HasFocus();
104 }
105
106 void SetStatusPopup( wxWindow* aPopup )
107 {
108 m_statusPopup = aPopup;
109 }
110
116 virtual bool SwitchBackend( GAL_TYPE aGalType );
117
122
126 inline GAL_TYPE GetBackend() const { return m_backend; }
127
133 KIGFX::GAL* GetGAL() const { return m_gal; }
134
140 virtual KIGFX::VIEW* GetView() const { return m_view; }
141
151
158 bool GetScreenshot( wxImage& aDstImage );
159
161 virtual void Refresh( bool aEraseBackground = true, const wxRect* aRect = nullptr ) override;
162
166 void ForceRefresh();
167
171 void RequestRefresh();
172
179
191 void ResizeGal( bool aForce = false );
192
201 void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
202
206 void StartDrawing();
207
212 void StopDrawing();
213
217 virtual void SetHighContrastLayer( int aLayer );
218
222 virtual void SetTopLayer( int aLayer );
223
224 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
225 {
226 wxASSERT( false );
227 }
228
233
234 bool IsDialogPreview() const { return m_parent != (wxWindow*) m_edaFrame; }
235
239 virtual void OnShow() {}
240
247 void SetStealsFocus( bool aStealsFocus ) { m_stealsFocus = aStealsFocus; }
248
252 void SetCurrentCursor( KICURSOR aCursor );
253
260 virtual BOX2I GetDefaultViewBBox() const { return BOX2I(); }
261
265 void OnEvent( wxEvent& aEvent );
266
276 bool DoRePaint( bool aAllowSkip = true );
277
281 std::shared_ptr<KIGFX::VIEW_OVERLAY> DebugOverlay();
282
283
287 void ClearDebugOverlay();
288
289
294
301
302 std::unique_ptr<PROF_COUNTER> m_PaintEventCounter;
303
308 virtual void prepareGridSources() {}
309
310protected:
311 virtual void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
312 void onSize( wxSizeEvent& aEvent );
313 void onEnter( wxMouseEvent& aEvent );
314 void onLostFocus( wxFocusEvent& aEvent );
315 void onIdle( wxIdleEvent& aEvent );
316 void onRefreshTimer( wxTimerEvent& aEvent );
317 void onShowEvent( wxShowEvent& aEvent );
318
319 bool recoverFromGalError( const std::exception& aErr );
320
321 wxWindow* m_parent;
323
324 std::chrono::steady_clock::time_point m_lastRepaintStart;
325 std::chrono::steady_clock::time_point m_lastRepaintEnd;
327
328 std::mutex m_refreshMutex;
329
332
335
338
341
344
347
349 std::unique_ptr<KIGFX::PAINTER> m_painter;
350
353
357
360
364
367
371
372 wxWindow* m_statusPopup;
373
375 std::shared_ptr<KIGFX::VIEW_OVERLAY> m_debugOverlay;
376
377 std::unique_ptr<KIPLATFORM::UI::TOUCHPAD_GESTURE_HANDLER> m_touchpadGestureHandler;
378};
379
380#endif
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
The base class for create windows for drawing purpose.
std::unique_ptr< PROF_COUNTER > m_PaintEventCounter
bool m_glRecoveryAttempted
Set after an OpenGL recovery attempt to prevent infinite retry loops.
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
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.
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
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,...
virtual BOX2I GetDefaultViewBBox() const
Return the bounding box of the view that should be used if model is not valid.
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.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
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 recoverFromGalError(const std::exception &aErr)
void ResizeGal(bool aForce=false)
Resize the GAL to the current client size of this panel.
bool m_drawing
True if GAL is currently redrawing the view.
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.
std::chrono::steady_clock::time_point m_lastRepaintStart
Timestamp of the last repaint start.
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::chrono::steady_clock::time_point m_lastRepaintEnd
Timestamp of the last repaint end.
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.
@ GAL_TYPE_LAST
Sentinel, do not use as a parameter.
@ GAL_TYPE_UNKNOWN
not specified: a GAL engine must be set by the client
@ GAL_TYPE_OPENGL
OpenGL implementation.
@ GAL_TYPE_CAIRO
Cairo implementation.
@ GAL_TYPE_NONE
GAL not used (the legacy wxDC engine is used)
virtual void prepareGridSources()
Hook for subclasses to push per-frame grid sources onto the GAL.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
bool m_MouseCapturedLost
used on wxMSW: true after a wxEVT_MOUSE_CAPTURE_LOST was received false after the mouse is recaptured...
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
void SetFocus() override
void onIdle(wxIdleEvent &aEvent)
void UpdateTouchpadGestureHandler()
Apply the current native touchpad gesture preference to the active backend window.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void UpdateOverlayExclusions()
Tell the backend which areas of this panel are covered by an overlaid infobar.
void onEnter(wxMouseEvent &aEvent)
void SetStatusPopup(wxWindow *aPopup)
std::unique_ptr< KIPLATFORM::UI::TOUCHPAD_GESTURE_HANDLER > m_touchpadGestureHandler
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.
bool DoRePaint(bool aAllowSkip=true)
Repaint the canvas, and fix scrollbar cursors.
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
void SetStealsFocus(bool aStealsFocus)
Set whether focus is taken on certain events (mouseover, keys, 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.
void onShowEvent(wxShowEvent &aEvent)
static constexpr bool GAL_FALLBACK_AVAILABLE
GAL_TYPE m_backend
Currently used GAL.
VECTOR2D m_lastCursorPosition
Last cursor position sent to GAL for drawing.
bool GetScreenshot(wxImage &aDstImage)
Capture the current canvas contents into aDstImage.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
Abstract interface for drawing on a 2D-surface.
Abstract interface for drawing on a 2D-surface.
An interface for classes handling user events controlling the view behavior such as zooming,...
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
An implementation of class VIEW_CONTROLS for wxWidgets library.
Owns a platform touchpad input registration for the lifetime of an input window.
Definition touchpad.h:50
A thread-safe event counter.
Definition profile.h:255
KICURSOR
Definition cursors.h:40
Message panel definition file.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
VECTOR2< double > VECTOR2D
Definition vector2d.h:682