KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 <gal/painter.h>
39#include <base_screen.h>
40#include <gal/cursors.h>
43#include <gal/cairo/cairo_gal.h>
44#include <math/vector2wx.h>
45
46
48#include <tool/tool_manager.h>
49
50#include <widgets/wx_infobar.h>
51
52#include <kiplatform/ui.h>
53
54#include <core/profile.h>
55
56#include <pgm_base.h>
57
58EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
59 const wxPoint& aPosition, const wxSize& aSize,
60 KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
61 wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ),
62 m_MouseCapturedLost( false ),
63 m_parent( aParentWindow ),
64 m_edaFrame( nullptr ),
65 m_lastRepaintStart( 0 ),
66 m_lastRepaintEnd( 0 ),
67 m_drawing( false ),
68 m_drawingEnabled( false ),
69 m_needIdleRefresh( false ),
70 m_gal( nullptr ),
71 m_view( nullptr ),
72 m_painter( nullptr ),
73 m_viewControls( nullptr ),
74 m_backend( GAL_TYPE_NONE ),
75 m_options( aOptions ),
76 m_eventDispatcher( nullptr ),
77 m_lostFocus( false ),
78 m_stealsFocus( true ),
79 m_statusPopup( nullptr )
80{
81 m_PaintEventCounter = std::make_unique<PROF_COUNTER>( "Draw panel paint events" );
82
83 SetLayoutDirection( wxLayout_LeftToRight );
84
85 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_parent );
86
87 // If we're in a dialog, we have to go looking for our parent frame
88 if( !m_edaFrame )
89 {
90 wxWindow* ancestor = aParentWindow->GetParent();
91
92 while( ancestor && !dynamic_cast<EDA_DRAW_FRAME*>( ancestor ) )
93 ancestor = ancestor->GetParent();
94
95 if( ancestor )
96 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( ancestor );
97 }
98
99 SwitchBackend( aGalType );
100 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
101
102 if( Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
103 {
104 ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
105 }
106 else
107 {
108 ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
109 }
110
111 EnableScrolling( false, false ); // otherwise Zoom Auto disables GAL canvas
112 KIPLATFORM::UI::SetOverlayScrolling( this, false ); // Prevent excessive repaint on GTK
113 KIPLATFORM::UI::ImmControl( this, false ); // Ensure our panel can't suck in IME events
114
115 Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), nullptr, this );
116 Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), nullptr,
117 this );
118 Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), nullptr,
119 this );
120
121 const wxEventType events[] = {
122 // Binding both EVT_CHAR and EVT_CHAR_HOOK ensures that all key events,
123 // especially special key like arrow keys, are handled by the GAL event dispatcher,
124 // and not sent to GUI without filtering, because they have a default action (scroll)
125 // that must not be called.
126 wxEVT_LEFT_UP,
127 wxEVT_LEFT_DOWN,
128 wxEVT_LEFT_DCLICK,
129 wxEVT_RIGHT_UP,
130 wxEVT_RIGHT_DOWN,
131 wxEVT_RIGHT_DCLICK,
132 wxEVT_MIDDLE_UP,
133 wxEVT_MIDDLE_DOWN,
134 wxEVT_MIDDLE_DCLICK,
135 wxEVT_AUX1_UP,
136 wxEVT_AUX1_DOWN,
137 wxEVT_AUX1_DCLICK,
138 wxEVT_AUX2_UP,
139 wxEVT_AUX2_DOWN,
140 wxEVT_AUX2_DCLICK,
141 wxEVT_MOTION,
142 wxEVT_MOUSEWHEEL,
143 wxEVT_CHAR,
144 wxEVT_CHAR_HOOK,
145 wxEVT_MAGNIFY,
147 };
148
149 for( wxEventType eventType : events )
150 Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::OnEvent ), nullptr,
152
153 // Set up timer to detect when drawing starts
154 m_refreshTimer.SetOwner( this );
155 Connect( m_refreshTimer.GetId(), wxEVT_TIMER,
156 wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), nullptr, this );
157
158 // Set up timer to execute OnShow() method when the window appears on the screen
159 m_onShowTimer.SetOwner( this );
160 Connect( m_onShowTimer.GetId(), wxEVT_TIMER,
161 wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onShowTimer ), nullptr, this );
162 m_onShowTimer.Start( 10 );
163}
164
165
167{
168 StopDrawing();
169
170 wxASSERT( !m_drawing );
171
172 delete m_viewControls;
173 delete m_view;
174 delete m_gal;
175}
176
177
179{
180 wxScrolledCanvas::SetFocus();
181 m_lostFocus = false;
182}
183
184
185void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
186{
187 DoRePaint();
188}
189
190
192{
193 if( !m_refreshMutex.try_lock() )
194 return false;
195
196 std::lock_guard<std::mutex> lock( m_refreshMutex, std::adopt_lock );
197
198 if( !m_drawingEnabled )
199 return false;
200
201 if( !m_gal->IsInitialized() || !m_gal->IsVisible() )
202 return false;
203
204 if( m_drawing )
205 return false;
206
207 m_lastRepaintStart = wxGetLocalTimeMillis();
208
209 // Repaint the canvas, and fix scrollbar cursors
210 // Usually called by a OnPaint event, but because it does not use a wxPaintDC,
211 // it can be called outside a wxPaintEvent.
212
213 // Update current zoom settings if the canvas is managed by a EDA frame
214 // (i.e. not by a preview panel in a dialog)
215 if( !IsDialogPreview() && GetParentEDAFrame() && GetParentEDAFrame()->GetScreen() )
217
218 if( Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
220
221 SCOPED_SET_RESET<bool> drawing( m_drawing, true );
222
223 ( *m_PaintEventCounter )++;
224
225 wxASSERT( m_painter );
226
227 KIGFX::RENDER_SETTINGS* settings =
228 static_cast<KIGFX::RENDER_SETTINGS*>( m_painter->GetSettings() );
229
230 PROF_TIMER cntUpd("view-upd-items");
231 PROF_TIMER cntTotal("view-total");
232 PROF_TIMER cntCtx("view-context-create");
233 PROF_TIMER cntCtxDestroy("view-context-destroy");
234 PROF_TIMER cntRedraw("view-redraw-rects");
235
236 bool isDirty = false;
237
238 cntTotal.Start();
239 try
240 {
241 cntUpd.Start();
242
243 try
244 {
246 }
247 catch( std::out_of_range& err )
248 {
249 // Don't do anything here but don't fail
250 // This can happen when we don't catch `at()` calls
251 wxString msg;
252 msg.Printf( wxT( "Out of Range error: %s" ), err.what() );
253 wxLogDebug( msg );
254 }
255
256 cntUpd.Stop();
257
258 // GAL_DRAWING_CONTEXT can throw in the dtor, so we need to scope
259 // the full lifetime inside the try block
260 {
261 cntCtx.Start();
263 cntCtx.Stop();
264
267 {
268 m_view->MarkDirty();
269 }
270
271 m_gal->SetClearColor( settings->GetBackgroundColor() );
272 m_gal->SetGridColor( settings->GetGridColor() );
273 m_gal->SetCursorColor( settings->GetCursorColor() );
274
275 // TODO: find why ClearScreen() must be called here in opengl mode
276 // and only if m_view->IsDirty() in Cairo mode to avoid display artifacts
277 // when moving the mouse cursor
280
281 if( m_view->IsDirty() )
282 {
283 if( m_backend != GAL_TYPE_OPENGL // Already called in opengl
285 {
287 }
288
290
291 // Grid has to be redrawn only when the NONCACHED target is redrawn
293 m_gal->DrawGrid();
294
295 cntRedraw.Start();
296 m_view->Redraw();
297 cntRedraw.Stop();
298 isDirty = true;
299 }
300
302
303 cntCtxDestroy.Start();
304 }
305
306 // ctx goes out of scope here so destructor would be called
307 cntCtxDestroy.Stop();
308 }
309 catch( std::exception& err )
310 {
311 if( GAL_FALLBACK != m_backend )
312 {
314
316 _( "Could not use OpenGL, falling back to software rendering" ),
317 wxString( err.what() ) );
318
319 StartDrawing();
320 }
321 else
322 {
323 // We're well and truly banjaxed if we get here without a fallback.
324 DisplayErrorMessage( m_parent, _( "Graphics error" ), wxString( err.what() ) );
325
326 StopDrawing();
327 }
328 }
329
330 if( isDirty )
331 {
332 KI_TRACE( traceGalProfile, "View timing: %s %s %s %s %s\n",
333 cntTotal.to_string(),
334 cntUpd.to_string(),
335 cntRedraw.to_string(),
336 cntCtx.to_string(),
337 cntCtxDestroy.to_string()
338 );
339 }
340
341 m_lastRepaintEnd = wxGetLocalTimeMillis();
342
343 return true;
344}
345
346
347void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent )
348{
349 // If we get a second wx update call before the first finishes, don't crash
350 if( m_gal->IsContextLocked() )
351 return;
352
354 wxSize clientSize = GetClientSize();
355 WX_INFOBAR* infobar = GetParentEDAFrame() ? GetParentEDAFrame()->GetInfoBar() : nullptr;
356
357 if( ToVECTOR2I( clientSize ) == m_gal->GetScreenPixelSize() )
358 return;
359
360 // Note: ( +1, +1 ) prevents an ugly black line on right and bottom on Mac
361 clientSize.x = std::max( 10, clientSize.x + 1 );
362 clientSize.y = std::max( 10, clientSize.y + 1 );
363
364 VECTOR2D bottom( 0, 0 );
365
366 if( m_view )
367 bottom = m_view->ToWorld( m_gal->GetScreenPixelSize(), true );
368
369 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
370
371 if( m_view )
372 {
373 if( infobar && infobar->IsLocked() )
374 {
375 VECTOR2D halfScreen( std::ceil( 0.5 * clientSize.x ), std::ceil( 0.5 * clientSize.y ) );
376 m_view->SetCenter( bottom - m_view->ToWorld( halfScreen, false ) );
377 }
378
381 }
382}
383
384
385void EDA_DRAW_PANEL_GAL::Refresh( bool aEraseBackground, const wxRect* aRect )
386{
387 if( !DoRePaint() )
388 m_needIdleRefresh = true;
389}
390
391
393{
394 if( !m_drawingEnabled )
395 {
396 if( m_gal && m_gal->IsInitialized() )
397 {
398 Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr,
399 this );
400
401 Connect( wxEVT_IDLE, wxIdleEventHandler( EDA_DRAW_PANEL_GAL::onIdle ), nullptr, this );
402
403 m_drawingEnabled = true;
404 }
405 else
406 {
407 // Try again soon
408 m_refreshTimer.StartOnce( 100 );
409 return;
410 }
411 }
412
413 DoRePaint();
414}
415
416
418{
419 m_eventDispatcher = aEventDispatcher;
420}
421
422
424{
425 // Start querying GAL if it is ready
426 m_refreshTimer.StartOnce( 100 );
427}
428
429
431{
432 m_refreshTimer.Stop();
433 m_drawingEnabled = false;
434
435 Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr, this );
436
437 Disconnect( wxEVT_IDLE, wxIdleEventHandler( EDA_DRAW_PANEL_GAL::onIdle ), nullptr, this );
438}
439
440
442{
443 // Set display settings for high contrast mode
445
446 SetTopLayer( aLayer );
447
448 rSettings->ClearHighContrastLayers();
449 rSettings->SetLayerIsHighContrast( aLayer );
450
452}
453
454
456{
458 m_view->SetTopLayer( aLayer );
460}
461
462
464{
465 // Do not do anything if the currently used GAL is correct
466 if( aGalType == m_backend && m_gal != nullptr )
467 return true;
468
469 VECTOR2D grid_size = m_gal ? m_gal->GetGridSize() : VECTOR2D();
470 bool grid_visibility = m_gal ? m_gal->GetGridVisibility() : true;
471 bool result = true; // assume everything will be fine
472
473 // Prevent refreshing canvas during backend switch
474 StopDrawing();
475
476 KIGFX::GAL* new_gal = nullptr;
477
478 try
479 {
480 switch( aGalType )
481 {
482 case GAL_TYPE_OPENGL:
483 {
484 wxString errormsg = KIGFX::OPENGL_GAL::CheckFeatures( m_options );
485
486 if( errormsg.empty() )
487 {
488 new_gal = new KIGFX::OPENGL_GAL( GetVcSettings(), m_options, this, this, this );
489 }
490 else
491 {
492 if( GAL_FALLBACK != aGalType )
493 {
494 aGalType = GAL_FALLBACK;
496 m_parent,
497 _( "Could not use OpenGL, falling back to software rendering" ),
498 errormsg );
499 new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this );
500 }
501 else
502 {
503 // We're well and truly banjaxed if we get here without a fallback.
504 DisplayInfoMessage( m_parent, _( "Could not use OpenGL" ), errormsg );
505 }
506 }
507 break;
508 }
509
510 case GAL_TYPE_CAIRO: new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this ); break;
511
512 default:
513 wxASSERT( false );
515 // warn about unhandled GAL canvas type, but continue with the fallback option
516
517 case GAL_TYPE_NONE:
518 // KIGFX::GAL is a stub - it actually does cannot display anything,
519 // but prevents code relying on GAL canvas existence from crashing
520 new_gal = new KIGFX::GAL( m_options );
521 break;
522 }
523 }
524 catch( std::runtime_error& err )
525 {
526 // Create a dummy GAL
527 new_gal = new KIGFX::GAL( m_options );
528 aGalType = GAL_TYPE_NONE;
529 DisplayError( m_parent, wxString( err.what() ) );
530 result = false;
531 }
532
533 // trigger update of the gal options in case they differ from the defaults
535
536 delete m_gal;
537 m_gal = new_gal;
538
539 wxSize clientSize = GetClientSize();
540 clientSize.x = std::max( 10, clientSize.x );
541 clientSize.y = std::max( 10, clientSize.y );
542 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
543
544 if( grid_size.x > 0 && grid_size.y > 0 )
545 m_gal->SetGridSize( grid_size );
546
547 m_gal->SetGridVisibility( grid_visibility );
548
549 // Make sure the cursor is set on the new canvas
550 SetCurrentCursor( KICURSOR::ARROW );
551
552 if( m_painter )
553 m_painter->SetGAL( m_gal );
554
555 if( m_view )
556 {
557 m_view->SetGAL( m_gal );
558 // Note: OpenGL requires reverse draw order when draw priority is enabled
560 }
561
562 m_backend = aGalType;
563
564 return result;
565}
566
567
568void EDA_DRAW_PANEL_GAL::OnEvent( wxEvent& aEvent )
569{
570 bool shouldSetFocus = m_lostFocus && m_stealsFocus
571 && !KIUI::IsInputControlFocused() // Don't steal from input controls
572 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
573 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
574
575 if( shouldSetFocus )
576 SetFocus();
577
578 if( !m_eventDispatcher )
579 aEvent.Skip();
580 else
582
583 // Give events time to process, based on last render duration
584 wxLongLong endDelta = wxGetLocalTimeMillis() - m_lastRepaintEnd;
585 long long timeLimit = ( m_lastRepaintEnd - m_lastRepaintStart ).GetValue() / 5;
586
587 timeLimit = std::clamp( timeLimit, 3LL, 150LL );
588
589 if( endDelta > timeLimit )
590 Refresh();
591 else
592 m_needIdleRefresh = true;
593}
594
595
596void EDA_DRAW_PANEL_GAL::onEnter( wxMouseEvent& aEvent )
597{
598 bool shouldSetFocus = m_stealsFocus
599 && !KIUI::IsInputControlFocused() // Don't steal from input controls
600 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
601 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
602
603 // Getting focus is necessary in order to receive key events properly
604 if( shouldSetFocus )
605 SetFocus();
606
607 aEvent.Skip();
608}
609
610
611void EDA_DRAW_PANEL_GAL::onLostFocus( wxFocusEvent& aEvent )
612{
613 m_lostFocus = true;
614
616
617 aEvent.Skip();
618}
619
620
621void EDA_DRAW_PANEL_GAL::onIdle( wxIdleEvent& aEvent )
622{
624 {
625 m_needIdleRefresh = false;
626 Refresh();
627 }
628
629 aEvent.Skip();
630}
631
632
633void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent )
634{
635 ForceRefresh();
636}
637
638
639void EDA_DRAW_PANEL_GAL::onShowTimer( wxTimerEvent& aEvent )
640{
641 if( m_gal && m_gal->IsInitialized() && m_gal->IsVisible() )
642 {
643 m_onShowTimer.Stop();
644 OnShow();
645 }
646}
647
648
650{
651 if( m_gal )
652 m_gal->SetNativeCursorStyle( aCursor );
653}
654
655
656std::shared_ptr<KIGFX::VIEW_OVERLAY> EDA_DRAW_PANEL_GAL::DebugOverlay()
657{
658 if( !m_debugOverlay )
659 {
660 m_debugOverlay.reset( new KIGFX::VIEW_OVERLAY() );
661 m_view->Add( m_debugOverlay.get() );
662 }
663
664 return m_debugOverlay;
665}
666
667
669{
670 if( m_debugOverlay )
671 {
672 m_view->Remove( m_debugOverlay.get() );
673 m_debugOverlay = nullptr;
674 }
675}
676
677
679{
680 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
681
682 KIGFX::VC_SETTINGS vcSettings;
683 vcSettings.m_warpCursor = cfg->m_Input.center_on_zoom;
685 vcSettings.m_autoPanSettingEnabled = cfg->m_Input.auto_pan;
687 vcSettings.m_horizontalPan = cfg->m_Input.horizontal_pan;
689 vcSettings.m_zoomSpeed = cfg->m_Input.zoom_speed;
690 vcSettings.m_zoomSpeedAuto = cfg->m_Input.zoom_speed_auto;
694 vcSettings.m_dragLeft = cfg->m_Input.drag_left;
695 vcSettings.m_dragMiddle = cfg->m_Input.drag_middle;
696 vcSettings.m_dragRight = cfg->m_Input.drag_right;
698
699 return vcSettings;
700}
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)
bool m_needIdleRefresh
True when canvas needs to be refreshed from idle handler.
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.
static KIGFX::VC_SETTINGS GetVcSettings()
Gets a populated View Controls settings object dervived from our program settings.
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.
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
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.
wxLongLong m_lastRepaintStart
Timestamp of the last repaint start.
@ 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.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
void SetFocus() override
void onIdle(wxIdleEvent &aEvent)
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.
wxLongLong m_lastRepaintEnd
Timestamp of the last repaint end.
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.
bool DoRePaint()
Repaint the canvas, and fix scrollbar cursors.
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 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:71
static wxString CheckFeatures(GAL_DISPLAY_OPTIONS &aOptions)
Checks OpenGL features.
Definition: opengl_gal.cpp:463
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:707
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
Definition: view.h:341
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:894
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:315
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:354
void ClearTargets()
Clear targets that are marked as dirty.
Definition: view.cpp:1136
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition: view.cpp:763
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:493
virtual void Redraw()
Immediately redraws the whole view.
Definition: view.cpp:1155
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:449
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
Definition: view.cpp:879
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:608
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
Definition: view.cpp:1432
bool IsDirty() const
Return true if any of the VIEW layers needs to be refreshened.
Definition: view.h:591
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:827
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:643
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:215
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:578
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:619
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:48
void Stop()
Save the time when this function was called, and set the counter stane to stop.
Definition: profile.h:87
void Start()
Start or restart the counter.
Definition: profile.h:76
std::string to_string()
Definition: profile.h:154
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: wx_infobar.h:75
bool IsLocked()
Returns true if the infobar is being updated.
Definition: wx_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:332
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:305
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:202
void ImmControl(wxWindow *aWindow, bool aEnable)
Configures the IME mode of a given control handle.
Definition: gtk/ui.cpp:319
bool IsWindowActive(wxWindow *aWindow)
Check to see if the given window is the currently active window (e.g.
Definition: gtk/ui.cpp:73
bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
Definition: ui_common.cpp:260
bool IsModalDialogFocused()
Definition: ui_common.cpp:314
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
MOUSE_DRAG_ACTION drag_right
MOUSE_DRAG_ACTION drag_middle
MOUSE_DRAG_ACTION drag_left
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
Definition: view_controls.h:43
MOUSE_DRAG_ACTION m_dragLeft
bool m_horizontalPan
Enable the accelerating zoom controller.
Definition: view_controls.h:92
bool m_autoPanSettingEnabled
Distance from cursor to VIEW edge when panning is active.
Definition: view_controls.h:77
bool m_focusFollowSchPcb
Flag for turning on autopanning.
Definition: view_controls.h:71
float m_autoPanAcceleration
If the cursor is allowed to be warped.
Definition: view_controls.h:86
MOUSE_DRAG_ACTION m_dragMiddle
int m_zoomSpeed
When true, ignore zoom_speed and pick a platform-specific default.
Definition: view_controls.h:98
int m_scrollModifierZoom
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
int m_scrollModifierPanH
What modifier key to enable vertical with the (vertical) scroll wheel.
bool m_warpCursor
Enable horizontal panning with the horizontal scroll/trackpad input.
Definition: view_controls.h:89
MOUSE_DRAG_ACTION m_dragRight
Is last cursor motion event coming from keyboard arrow cursor motion action.
bool m_zoomAcceleration
Zoom speed for the non-accelerating zoom controller.
Definition: view_controls.h:95
bool m_zoomSpeedAuto
What modifier key to enable zoom with the (vertical) scroll wheel.
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587
VECTOR2I ToVECTOR2I(const wxSize &aSize)
Definition: vector2wx.h:30
WX_VIEW_CONTROLS class definition.