KiCad PCB EDA Suite
draw_panel_gal.cpp
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-2017 CERN
5 * Copyright (C) 2013-2021 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, 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#include <confirm.h>
28#include <eda_draw_frame.h>
29#include <kiface_base.h>
30#include <macros.h>
31#include <scoped_set_reset.h>
33#include <trace_helpers.h>
34
36#include <view/view.h>
38#include <painter.h>
39#include <base_screen.h>
40#include <gal/cursors.h>
43#include <gal/cairo/cairo_gal.h>
44
45
47#include <tool/tool_manager.h>
48
49#include <widgets/infobar.h>
50
51#include <kiplatform/ui.h>
52
53#include <profile.h>
54
55#include <pgm_base.h>
56
57EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
58 const wxPoint& aPosition, const wxSize& aSize,
59 KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
60 wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ),
61 m_edaFrame( nullptr ),
62 m_gal( nullptr ),
63 m_view( nullptr ),
64 m_painter( nullptr ),
65 m_viewControls( nullptr ),
66 m_backend( GAL_TYPE_NONE ),
67 m_options( aOptions ),
68 m_eventDispatcher( nullptr ),
69 m_lostFocus( false ),
70 m_stealsFocus( true ),
71 m_statusPopup( nullptr )
72{
73 m_parent = aParentWindow;
74 m_MouseCapturedLost = false;
75
76 m_PaintEventCounter = std::make_unique<PROF_COUNTER>( "Draw panel paint events" );
77
78 SetLayoutDirection( wxLayout_LeftToRight );
79
80 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_parent );
81
82 // If we're in a dialog, we have to go looking for our parent frame
83 if( !m_edaFrame )
84 {
85 wxWindow* ancestor = aParentWindow->GetParent();
86
87 while( ancestor && !dynamic_cast<EDA_DRAW_FRAME*>( ancestor ) )
88 ancestor = ancestor->GetParent();
89
90 if( ancestor )
91 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( ancestor );
92 }
93
94 SwitchBackend( aGalType );
95 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
96
97 if( Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
98 {
99 ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
100 }
101 else
102 {
103 ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
104 }
105
106 EnableScrolling( false, false ); // otherwise Zoom Auto disables GAL canvas
107 KIPLATFORM::UI::SetOverlayScrolling( this, false ); // Prevent excessive repaint on GTK
108
109 Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), nullptr, this );
110 Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), nullptr,
111 this );
112 Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), nullptr,
113 this );
114
115 const wxEventType events[] = {
116 // Binding both EVT_CHAR and EVT_CHAR_HOOK ensures that all key events,
117 // especially special key like arrow keys, are handled by the GAL event dispatcher,
118 // and not sent to GUI without filtering, because they have a default action (scroll)
119 // that must not be called.
120 wxEVT_LEFT_UP,
121 wxEVT_LEFT_DOWN,
122 wxEVT_LEFT_DCLICK,
123 wxEVT_RIGHT_UP,
124 wxEVT_RIGHT_DOWN,
125 wxEVT_RIGHT_DCLICK,
126 wxEVT_MIDDLE_UP,
127 wxEVT_MIDDLE_DOWN,
128 wxEVT_MIDDLE_DCLICK,
129 wxEVT_AUX1_UP,
130 wxEVT_AUX1_DOWN,
131 wxEVT_AUX1_DCLICK,
132 wxEVT_AUX2_UP,
133 wxEVT_AUX2_DOWN,
134 wxEVT_AUX2_DCLICK,
135 wxEVT_MOTION,
136 wxEVT_MOUSEWHEEL,
137 wxEVT_CHAR,
138 wxEVT_CHAR_HOOK,
139#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
140 wxEVT_MAGNIFY,
141#endif
143 };
144
145 for( wxEventType eventType : events )
146 Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::OnEvent ), nullptr,
148
149 m_pendingRefresh = false;
150 m_drawing = false;
151 m_drawingEnabled = false;
152
153 m_minRefreshPeriod = 13; // 77 FPS (minus render time) by default
154
155 // Set up timer that prevents too frequent redraw commands
156 m_refreshTimer.SetOwner( this );
157 Connect( m_refreshTimer.GetId(), wxEVT_TIMER,
158 wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), nullptr, this );
159
160 // Set up timer to execute OnShow() method when the window appears on the screen
161 m_onShowTimer.SetOwner( this );
162 Connect( m_onShowTimer.GetId(), wxEVT_TIMER,
163 wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onShowTimer ), nullptr, this );
164 m_onShowTimer.Start( 10 );
165}
166
167
169{
170 StopDrawing();
171
172 wxASSERT( !m_drawing );
173
174 delete m_viewControls;
175 delete m_view;
176 delete m_gal;
177}
178
179
181{
182 wxScrolledCanvas::SetFocus();
183 m_lostFocus = false;
184}
185
186
187void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
188{
189 DoRePaint();
190}
191
192
194{
195 if( !m_refreshMutex.try_lock() )
196 return;
197
198 std::lock_guard<std::mutex> lock( m_refreshMutex, std::adopt_lock );
199
200 // Repaint the canvas, and fix scrollbar cursors
201 // Usually called by a OnPaint event, but because it does not use a wxPaintDC,
202 // it can be called outside a wxPaintEvent.
203
204 // Update current zoom settings if the canvas is managed by a EDA frame
205 // (i.e. not by a preview panel in a dialog)
206 if( !IsDialogPreview() && GetParentEDAFrame() && GetParentEDAFrame()->GetScreen() )
208
209 if( Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
211
212 if( !m_drawingEnabled )
213 return;
214
215 if( !m_gal->IsVisible() )
216 return;
217
218 m_pendingRefresh = false;
219
220 if( m_drawing )
221 return;
222
223 SCOPED_SET_RESET<bool> drawing( m_drawing, true );
224
225 ( *m_PaintEventCounter )++;
226
227 wxASSERT( m_painter );
228
229 KIGFX::RENDER_SETTINGS* settings =
230 static_cast<KIGFX::RENDER_SETTINGS*>( m_painter->GetSettings() );
231
232 PROF_TIMER cntUpd("view-upd-items");
233 PROF_TIMER cntTotal("view-total");
234 PROF_TIMER cntCtx("view-context-create");
235 PROF_TIMER cntCtxDestroy("view-context-destroy");
236 PROF_TIMER cntRedraw("view-redraw-rects");
237
238 bool isDirty = false;
239
240 cntTotal.Start();
241 try
242 {
243 cntUpd.Start();
244
245 try
246 {
248 }
249 catch( std::out_of_range& err )
250 {
251 // Don't do anything here but don't fail
252 // This can happen when we don't catch `at()` calls
253 wxString msg;
254 msg.Printf( wxT( "Out of Range error: %s" ), err.what() );
255 wxLogDebug( msg );
256 }
257
258 cntUpd.Stop();
259
260 // GAL_DRAWING_CONTEXT can throw in the dtor, so we need to scope
261 // the full lifetime inside the try block
262 {
263 cntCtx.Start();
265 cntCtx.Stop();
266
269 {
270 m_view->MarkDirty();
271 }
272
273 m_gal->SetClearColor( settings->GetBackgroundColor() );
274 m_gal->SetGridColor( settings->GetGridColor() );
275 m_gal->SetCursorColor( settings->GetCursorColor() );
276
277 // TODO: find why ClearScreen() must be called here in opengl mode
278 // and only if m_view->IsDirty() in Cairo mode to avoid display artifacts
279 // when moving the mouse cursor
282
283 if( m_view->IsDirty() )
284 {
285 if( m_backend != GAL_TYPE_OPENGL // Already called in opengl
287 {
289 }
290
292
293 // Grid has to be redrawn only when the NONCACHED target is redrawn
295 m_gal->DrawGrid();
296
297 cntRedraw.Start();
298 m_view->Redraw();
299 cntRedraw.Stop();
300 isDirty = true;
301 }
302
304
305 cntCtxDestroy.Start();
306 }
307
308 // ctx goes out of scope here so destructor would be called
309 cntCtxDestroy.Stop();
310 }
311 catch( std::exception& err )
312 {
313 if( GAL_FALLBACK != m_backend )
314 {
316
318 _( "Could not use OpenGL, falling back to software rendering" ),
319 wxString( err.what() ) );
320 }
321 else
322 {
323 // We're well and truly banjaxed if we get here without a fallback.
324 DisplayInfoMessage( m_parent, _( "Could not use OpenGL" ), wxString( err.what() ) );
325 }
326 }
327
328 if( isDirty )
329 {
330 KI_TRACE( traceGalProfile, "View timing: %s %s %s %s %s\n",
331 cntTotal.to_string(),
332 cntUpd.to_string(),
333 cntRedraw.to_string(),
334 cntCtx.to_string(),
335 cntCtxDestroy.to_string()
336 );
337 }
338
339 m_lastRefresh = wxGetLocalTimeMillis();
340}
341
342
343void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent )
344{
345 // If we get a second wx update call before the first finishes, don't crash
346 if( m_gal->IsContextLocked() )
347 return;
348
350 wxSize clientSize = GetClientSize();
351 WX_INFOBAR* infobar = GetParentEDAFrame() ? GetParentEDAFrame()->GetInfoBar() : nullptr;
352
353 if( VECTOR2I( clientSize ) == m_gal->GetScreenPixelSize() )
354 return;
355
356 clientSize.x = std::max( 10, clientSize.x );
357 clientSize.y = std::max( 10, clientSize.y );
358
359 VECTOR2D bottom( 0, 0 );
360
361 if( m_view )
362 bottom = m_view->ToWorld( m_gal->GetScreenPixelSize(), true );
363
364 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
365
366 if( m_view )
367 {
368 if( infobar && infobar->IsLocked() )
369 m_view->SetCenter( bottom - m_view->ToWorld( clientSize, false ) / 2.0 );
370
373 }
374}
375
376
377void EDA_DRAW_PANEL_GAL::Refresh( bool aEraseBackground, const wxRect* aRect )
378{
379 wxLongLong t = wxGetLocalTimeMillis();
380 wxLongLong delta = t - m_lastRefresh;
381
382 // If it has been too long since the last frame (possible depending on platform timer latency),
383 // just do a refresh. Otherwise, start the refresh timer if it hasn't already been started.
384 // This ensures that we will render often enough but not too often.
386 {
387 if( !m_pendingRefresh )
388 ForceRefresh();
389
390 m_refreshTimer.Start( m_minRefreshPeriod, true );
391 }
392 else if( !m_refreshTimer.IsRunning() )
393 {
394 m_refreshTimer.Start( ( m_minRefreshPeriod - delta ).ToLong(), true );
395 }
396}
397
398
400{
401 m_pendingRefresh = true;
402 DoRePaint();
403}
404
405
407{
408 m_eventDispatcher = aEventDispatcher;
409}
410
411
413{
414 // Start querying GAL if it is ready
415 m_refreshTimer.StartOnce( 100 );
416}
417
418
420{
421 m_refreshTimer.Stop();
422 m_drawingEnabled = false;
423 Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr, this );
424 m_pendingRefresh = false;
425}
426
427
429{
430 // Set display settings for high contrast mode
432
433 SetTopLayer( aLayer );
434
435 rSettings->ClearHighContrastLayers();
436 rSettings->SetLayerIsHighContrast( aLayer );
437
439}
440
441
443{
445 m_view->SetTopLayer( aLayer );
447}
448
449
451{
452 // Do not do anything if the currently used GAL is correct
453 if( aGalType == m_backend && m_gal != nullptr )
454 return true;
455
456 VECTOR2D grid_size = m_gal ? m_gal->GetGridSize() : VECTOR2D();
457 bool grid_visibility = m_gal ? m_gal->GetGridVisibility() : true;
458 bool result = true; // assume everything will be fine
459
460 // Prevent refreshing canvas during backend switch
461 StopDrawing();
462
463 KIGFX::GAL* new_gal = nullptr;
464
465 try
466 {
467 switch( aGalType )
468 {
469 case GAL_TYPE_OPENGL:
470 {
471 wxString errormsg = KIGFX::OPENGL_GAL::CheckFeatures( m_options );
472
473 if( errormsg.empty() )
474 {
475 new_gal = new KIGFX::OPENGL_GAL( m_options, this, this, this );
476 }
477 else
478 {
479 if( GAL_FALLBACK != aGalType )
480 {
481 aGalType = GAL_FALLBACK;
483 m_parent,
484 _( "Could not use OpenGL, falling back to software rendering" ),
485 errormsg );
486 new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this );
487 }
488 else
489 {
490 // We're well and truly banjaxed if we get here without a fallback.
491 DisplayInfoMessage( m_parent, _( "Could not use OpenGL" ), errormsg );
492 }
493 }
494 break;
495 }
496
497 case GAL_TYPE_CAIRO: new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this ); break;
498
499 default:
500 wxASSERT( false );
502 // warn about unhandled GAL canvas type, but continue with the fallback option
503
504 case GAL_TYPE_NONE:
505 // KIGFX::GAL is a stub - it actually does cannot display anything,
506 // but prevents code relying on GAL canvas existence from crashing
507 new_gal = new KIGFX::GAL( m_options );
508 break;
509 }
510 }
511 catch( std::runtime_error& err )
512 {
513 // Create a dummy GAL
514 new_gal = new KIGFX::GAL( m_options );
515 aGalType = GAL_TYPE_NONE;
516 DisplayError( m_parent, wxString( err.what() ) );
517 result = false;
518 }
519
520 // trigger update of the gal options in case they differ from the defaults
522
523 delete m_gal;
524 m_gal = new_gal;
525
526 wxSize clientSize = GetClientSize();
527 clientSize.x = std::max( 10, clientSize.x );
528 clientSize.y = std::max( 10, clientSize.y );
529 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
530
531 if( grid_size.x > 0 && grid_size.y > 0 )
532 m_gal->SetGridSize( grid_size );
533
534 m_gal->SetGridVisibility( grid_visibility );
535
536 if( m_gal->GetSwapInterval() != 0 )
537 {
538 // In theory this could be 0 but then more CPU cycles will be wasted in SwapBuffers
540 }
541
542 // Make sure the cursor is set on the new canvas
544
545 if( m_painter )
546 m_painter->SetGAL( m_gal );
547
548 if( m_view )
549 {
550 m_view->SetGAL( m_gal );
551 // Note: OpenGL requires reverse draw order when draw priority is enabled
553 }
554
555 m_backend = aGalType;
556
557 return result;
558}
559
560
561void EDA_DRAW_PANEL_GAL::OnEvent( wxEvent& aEvent )
562{
563 bool shouldSetFocus = m_lostFocus && m_stealsFocus
564 && !KIUI::IsInputControlFocused() // Don't steal from input controls
565 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
566 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
567
568 if( shouldSetFocus )
569 SetFocus();
570
571 if( !m_eventDispatcher )
572 aEvent.Skip();
573 else
575
576 Refresh();
577}
578
579
580void EDA_DRAW_PANEL_GAL::onEnter( wxMouseEvent& aEvent )
581{
582 bool shouldSetFocus = m_stealsFocus
583 && !KIUI::IsInputControlFocused() // Don't steal from input controls
584 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
585 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
586
587 // Getting focus is necessary in order to receive key events properly
588 if( shouldSetFocus )
589 SetFocus();
590
591 aEvent.Skip();
592}
593
594
595void EDA_DRAW_PANEL_GAL::onLostFocus( wxFocusEvent& aEvent )
596{
597 m_lostFocus = true;
598
600
601 aEvent.Skip();
602}
603
604
605void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent )
606{
607 if( !m_drawingEnabled )
608 {
609 if( m_gal && m_gal->IsInitialized() )
610 {
611 m_pendingRefresh = true;
612 Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr,
613 this );
614 m_drawingEnabled = true;
615 }
616 else
617 {
618 // Try again soon
619 m_refreshTimer.StartOnce( 100 );
620 return;
621 }
622 }
623
624 DoRePaint();
625}
626
627
628void EDA_DRAW_PANEL_GAL::onShowTimer( wxTimerEvent& aEvent )
629{
630 if( m_gal && m_gal->IsVisible() )
631 {
632 m_onShowTimer.Stop();
633 OnShow();
634 }
635}
636
637
639{
640 if( m_gal )
641 m_gal->SetNativeCursorStyle( aCursor );
642}
643
644
645std::shared_ptr<KIGFX::VIEW_OVERLAY> EDA_DRAW_PANEL_GAL::DebugOverlay()
646{
647 if( !m_debugOverlay )
648 {
649 m_debugOverlay.reset( new KIGFX::VIEW_OVERLAY() );
650 m_view->Add( m_debugOverlay.get() );
651 }
652
653 return m_debugOverlay;
654}
655
656
658{
659 if( m_debugOverlay )
660 {
661 m_view->Remove( m_debugOverlay.get() );
662 m_debugOverlay = nullptr;
663 }
664}
BASE_SCREEN class implementation.
VECTOR2D m_ScrollCenter
Current scroll center point in logical units.
Definition: base_screen.h:100
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)
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.
int m_minRefreshPeriod
A minimum delay before another draw can start.
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.
wxLongLong m_lastRefresh
Last timestamp when the panel was refreshed.
bool m_pendingRefresh
Is there a redraw event requested?
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
Update the board display after modifying it by a python script (note: it is automatically called by a...
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_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.
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.)
void SetFocus() override
void DoRePaint()
Repaint the canvas, and fix scrollbar cursors.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void onEnter(wxMouseEvent &aEvent)
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.
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.
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 int GetSwapInterval() const
Return the swap interval. -1 for adaptive, 0 for disabled/unknown.
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 void DrawGrid()
virtual bool IsContextLocked()
Checks the state of the context lock.
bool GetGridVisibility() const
virtual void ClearScreen()
Clear the screen.
virtual bool SetNativeCursorStyle(KICURSOR aCursor)
Set the cursor in the native panel.
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.
Definition: opengl_gal.h:70
static wxString CheckFeatures(GAL_DISPLAY_OPTIONS &aOptions)
Checks OpenGL features.
Definition: opengl_gal.cpp:360
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.
Definition: view.h:698
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
Definition: view.h:339
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:889
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:316
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:346
void ClearTargets()
Clear targets that are marked as dirty.
Definition: view.cpp:1111
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition: view.cpp:758
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:489
virtual void Redraw()
Immediately redraws the whole view.
Definition: view.cpp:1130
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:445
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
Definition: view.cpp:874
bool IsTargetDirty(int aTarget) const
Return true if any of layers belonging to the target or the target itself should be redrawn.
Definition: view.h:606
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
Definition: view.cpp:1398
bool IsDirty() const
Return true if any of the VIEW layers needs to be refreshened.
Definition: view.h:589
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.
Definition: view.cpp:822
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:641
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:213
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:574
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:617
VECTOR2D GetCursorPosition(bool aSnappingEnabled) const override
<
void UpdateScrollbars()
End any mouse drag action still in progress.
static const wxEventType EVT_REFRESH_MOUSE
A small class to help profiling.
Definition: profile.h:47
void Stop()
Save the time when this function was called, and set the counter stane to stop.
Definition: profile.h:86
void Start()
Start or restart the counter.
Definition: profile.h:75
std::string to_string()
Definition: profile.h:153
RAII class that sets an value at construction and resets it to the original value at destruction.
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:75
bool IsLocked()
Returns true if the infobar is being updated.
Definition: infobar.h:212
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:320
This file is part of the common library.
KICURSOR
Definition: cursors.h:34
#define _(s)
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 ...
Definition: macros.h:83
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:49
@ TARGET_CACHED
Main rendering target (cached)
Definition: definitions.h:48
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
void SetOverlayScrolling(const wxWindow *aWindow, bool overlay)
Used to set overlay/non-overlay scrolling mode in a window.
Definition: gtk/ui.cpp:133
bool IsWindowActive(wxWindow *aWindow)
Check to see if the given window is the currently active window (e.g.
Definition: gtk/ui.cpp:50
bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
Definition: ui_common.cpp:253
bool IsModalDialogFocused()
Definition: ui_common.cpp:303
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
constexpr int delta
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618
WX_VIEW_CONTROLS class definition.