KiCad PCB EDA Suite
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 (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
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, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #ifndef PANELGAL_WXSTRUCT_H
29 #define PANELGAL_WXSTRUCT_H
30 
31 #include <wx/window.h>
32 #include <wx/timer.h>
33 #include <wx/grid.h> // needed for MSVC to see wxScrolledCanvas indirectly exported
34 #include <math/box2.h>
35 #include <math/vector2d.h>
36 #include <msgpanel.h>
37 #include <memory>
38 #include <common.h>
39 
40 class BOARD;
41 class EDA_DRAW_FRAME;
42 class TOOL_DISPATCHER;
43 
44 namespace KIGFX
45 {
46 class GAL;
47 class VIEW;
48 class WX_VIEW_CONTROLS;
49 class VIEW_CONTROLS;
50 class PAINTER;
51 class GAL_DISPLAY_OPTIONS;
52 }
53 
54 
55 class EDA_DRAW_PANEL_GAL : public wxScrolledCanvas
56 {
57 public:
58  enum GAL_TYPE {
64  };
65 
66 #ifdef __WXMAC__
67  // Cairo doesn't work on OSX so we really have no fallback available.
68  static constexpr GAL_TYPE GAL_FALLBACK = GAL_TYPE_OPENGL;
69 #else
70  static constexpr GAL_TYPE GAL_FALLBACK = GAL_TYPE_CAIRO;
71 #endif
72 
81  EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
82  const wxPoint& aPosition, const wxSize& aSize,
84  GAL_TYPE aGalType = GAL_TYPE_OPENGL );
86 
87  virtual void SetFocus() override;
88 
94  virtual bool SwitchBackend( GAL_TYPE aGalType );
95 
100  inline GAL_TYPE GetBackend() const { return m_backend; }
101 
107  KIGFX::GAL* GetGAL() const { return m_gal; }
108 
114  virtual KIGFX::VIEW* GetView() const { return m_view; }
115 
122  {
124  }
125 
127  virtual void Refresh( bool aEraseBackground = true, const wxRect* aRect = NULL ) override;
128 
133  void ForceRefresh();
134 
142  void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
143 
148  void StartDrawing();
149 
155  void StopDrawing();
156 
161  virtual void SetHighContrastLayer( int aLayer );
162 
167  virtual void SetTopLayer( int aLayer );
168 
169  virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
170  {
171  wxASSERT( false );
172  }
173 
179 
180  bool IsDialogPreview() const { return m_parent != (wxWindow*) m_edaFrame; }
181 
186  virtual void OnShow() {}
187 
193  void SetStealsFocus( bool aStealsFocus ) { m_stealsFocus = aStealsFocus; }
194 
199  void SetCurrentCursor( wxStockCursor aStockCursorID );
200  void SetCurrentCursor( const wxCursor& aCursor );
201 
208  virtual BOX2I GetDefaultViewBBox() const { return BOX2I(); }
209 
213  void OnEvent( wxEvent& aEvent );
214 
220  void DoRePaint();
221 
222 protected:
223 
224  virtual void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
225  void onSize( wxSizeEvent& aEvent );
226  void onEnter( wxEvent& aEvent );
227  void onLostFocus( wxFocusEvent& aEvent );
228  void onRefreshTimer( wxTimerEvent& aEvent );
229  void onShowTimer( wxTimerEvent& aEvent );
230  void onSetCursor( wxSetCursorEvent& event );
231 
232  static const int MinRefreshPeriod = 17;
233 
234  wxCursor m_currentCursor;
235 
236  wxWindow* m_parent;
238 
239  wxLongLong m_lastRefresh;
241  wxTimer m_refreshTimer;
242 
244  bool m_drawing;
245 
248 
250  wxTimer m_onShowTimer;
251 
254 
257 
259  std::unique_ptr<KIGFX::PAINTER> m_painter;
260 
263 
267 
270 
274 
278 };
279 
280 #endif
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.
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
virtual void SetHighContrastLayer(int aLayer)
Function SetHighContrastLayer Takes care of display settings for the given layer to be displayed in h...
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
GAL_TYPE m_backend
Currently used GAL.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library.
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Function SwitchBackend Switches method of rendering graphics.
KIGFX::GAL_DISPLAY_OPTIONS & m_options
virtual void OnShow()
Function OnShow() Called when the window is shown for the first time.
static constexpr GAL_TYPE GAL_FALLBACK
void onLostFocus(wxFocusEvent &aEvent)
void DoRePaint()
Repaint the canvas, and fix scrollbar cursors Usually called by a OnPaint event, but because it do no...
Sentinel, do not use as a parameter.
void onShowTimer(wxTimerEvent &aEvent)
The base class for create windows for drawing purpose.
not specified: a GAL engine must be set by the client
void onRefreshTimer(wxTimerEvent &aEvent)
bool m_drawing
True if GAL is currently redrawing the view.
wxWindow * m_parent
Pointer to the parent window.
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent))
#define NULL
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)
Function SetTopLayer Moves the selected layer to the top, so it is displayed above all others.
void SetStealsFocus(bool aStealsFocus)
Set whether focus is taken on certain events (mouseover, keys, etc).
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
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.
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
bool m_lostFocus
Flag to indicate that focus should be regained on the next mouse event.
virtual KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
virtual void SetFocus() override
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
void onSetCursor(wxSetCursorEvent &event)
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
void onSize(wxSizeEvent &aEvent)
void StartDrawing()
Function StartDrawing() Begins 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...
TOOL_DISPATCHER * m_eventDispatcher
Processes and forwards events to tools.
wxTimer m_onShowTimer
Timer used to execute OnShow() when the window finally appears on the screen.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Function GetParentEDAFrame() 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.
The common library.
wxLongLong m_lastRefresh
Last timestamp when the panel was refreshed.
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
void onEnter(wxEvent &aEvent)
VIEW.
Definition: view.h:61
wxCursor m_currentCursor
Current mouse cursor shape id.
bool m_stealsFocus
Flag to indicate whether the panel should take focus at certain times (when moused over,...
Message panel definition file.
virtual BOX2I GetDefaultViewBBox() const
Returns the bounding box of the view that should be used if model is not valid For example,...
void StopDrawing()
Function StopDrawing() Prevents the GAL canvas from further drawing till it is recreated or StartDraw...
Class GAL is the abstract interface for drawing on a 2D-surface.