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 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, 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 <eda_draw_frame.h>
28#include <kiface_base.h>
29#include <macros.h>
30#include <scoped_set_reset.h>
32#include <trace_helpers.h>
33
35#include <view/view.h>
37#include <gal/painter.h>
38#include <base_screen.h>
39#include <gal/cursors.h>
42#include <gal/cairo/cairo_gal.h>
43#include <math/vector2wx.h>
44
45
47#include <tool/tool_manager.h>
48
49#include <widgets/wx_infobar.h>
50
51#include <kiplatform/ui.h>
52
53#include <core/profile.h>
54
55#include <pgm_base.h>
56#include <confirm.h>
57
58
64static const wxChar traceDrawPanel[] = wxT( "KICAD_DRAW_PANEL" );
65
66
67EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
68 const wxPoint& aPosition, const wxSize& aSize,
69 KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
70 wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ),
71 m_MouseCapturedLost( false ),
72 m_parent( aParentWindow ),
73 m_edaFrame( nullptr ),
76 m_drawing( false ),
77 m_drawingEnabled( false ),
78 m_needIdleRefresh( false ),
79 m_gal( nullptr ),
80 m_view( nullptr ),
81 m_painter( nullptr ),
82 m_viewControls( nullptr ),
84 m_options( aOptions ),
85 m_eventDispatcher( nullptr ),
86 m_lostFocus( false ),
87 m_stealsFocus( true ),
88 m_statusPopup( nullptr )
89{
90#ifdef _WIN32
91 // need to fix broken cairo rendering on Windows with wx 3.3
92 SetDoubleBuffered( false );
93#endif
94 m_PaintEventCounter = std::make_unique<PROF_COUNTER>( "Draw panel paint events" );
95
96 if( Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
97 ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
98 else
99 ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
100
101 SetLayoutDirection( wxLayout_LeftToRight );
102
103 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_parent );
104
105 // If we're in a dialog, we have to go looking for our parent frame
106 if( !m_edaFrame )
107 {
108 wxWindow* ancestor = aParentWindow->GetParent();
109
110 while( ancestor && !dynamic_cast<EDA_DRAW_FRAME*>( ancestor ) )
111 ancestor = ancestor->GetParent();
112
113 if( ancestor )
114 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( ancestor );
115 }
116
117 SwitchBackend( aGalType );
118 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
119
120 EnableScrolling( false, false ); // otherwise Zoom Auto disables GAL canvas
121 KIPLATFORM::UI::SetOverlayScrolling( this, false ); // Prevent excessive repaint on GTK
122 KIPLATFORM::UI::ImmControl( this, false ); // Ensure our panel can't suck in IME events
123
124 Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), nullptr, this );
125 Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), nullptr,
126 this );
127 Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), nullptr,
128 this );
129
130 const wxEventType events[] = {
131 // Binding both EVT_CHAR and EVT_CHAR_HOOK ensures that all key events,
132 // especially special key like arrow keys, are handled by the GAL event dispatcher,
133 // and not sent to GUI without filtering, because they have a default action (scroll)
134 // that must not be called.
135 wxEVT_LEFT_UP,
136 wxEVT_LEFT_DOWN,
137 wxEVT_LEFT_DCLICK,
138 wxEVT_RIGHT_UP,
139 wxEVT_RIGHT_DOWN,
140 wxEVT_RIGHT_DCLICK,
141 wxEVT_MIDDLE_UP,
142 wxEVT_MIDDLE_DOWN,
143 wxEVT_MIDDLE_DCLICK,
144 wxEVT_AUX1_UP,
145 wxEVT_AUX1_DOWN,
146 wxEVT_AUX1_DCLICK,
147 wxEVT_AUX2_UP,
148 wxEVT_AUX2_DOWN,
149 wxEVT_AUX2_DCLICK,
150 wxEVT_MOTION,
151 wxEVT_MOUSEWHEEL,
152 wxEVT_CHAR,
153 wxEVT_CHAR_HOOK,
154 wxEVT_MAGNIFY,
156 };
157
158 for( wxEventType eventType : events )
159 Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::OnEvent ), nullptr,
161
162 // Set up timer to detect when drawing starts
163 m_refreshTimer.SetOwner( this );
164 Connect( m_refreshTimer.GetId(), wxEVT_TIMER,
165 wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), nullptr, this );
166
167 Connect( wxEVT_SHOW, wxShowEventHandler( EDA_DRAW_PANEL_GAL::onShowEvent ), nullptr, this );
168}
169
170
172{
173 // Ensure EDA_DRAW_PANEL_GAL::onShowEvent is not fired during Dtor process
174 Disconnect( wxEVT_SHOW, wxShowEventHandler( EDA_DRAW_PANEL_GAL::onShowEvent ) );
175 StopDrawing();
176
177 wxASSERT( !m_drawing );
178
179 delete m_viewControls;
180 delete m_view;
181 delete m_gal;
182 m_gal = nullptr; // Ensure OnShow is not called
183}
184
185
187{
189 wxScrolledCanvas::SetFocus();
190 m_lostFocus = false;
191}
192
193
194void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
195{
196 DoRePaint();
197}
198
199
201{
202 if( !m_refreshMutex.try_lock() )
203 return false;
204
205 std::lock_guard<std::mutex> lock( m_refreshMutex, std::adopt_lock );
206
207 if( !m_drawingEnabled )
208 return false;
209
210 if( !m_gal->IsInitialized() || !m_gal->IsVisible() || m_gal->IsContextLocked() )
211 return false;
212
213 if( m_drawing )
214 return false;
215
216 m_lastRepaintStart = wxGetLocalTimeMillis();
217
218 // Repaint the canvas, and fix scrollbar cursors
219 // Usually called by a OnPaint event, but because it does not use a wxPaintDC,
220 // it can be called outside a wxPaintEvent.
221
222 // Update current zoom settings if the canvas is managed by a EDA frame
223 // (i.e. not by a preview panel in a dialog)
224 if( !IsDialogPreview() && GetParentEDAFrame() && GetParentEDAFrame()->GetScreen() )
226
227 if( Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
228 m_viewControls->UpdateScrollbars();
229
230 SCOPED_SET_RESET<bool> drawing( m_drawing, true );
231
232 ( *m_PaintEventCounter )++;
233
234 wxASSERT( m_painter );
235
236 KIGFX::RENDER_SETTINGS* settings =
237 static_cast<KIGFX::RENDER_SETTINGS*>( m_painter->GetSettings() );
238
239 PROF_TIMER cntUpd("view-upd-items");
240 PROF_TIMER cntTotal("view-total");
241 PROF_TIMER cntCtx("view-context-create");
242 PROF_TIMER cntCtxDestroy("view-context-destroy");
243 PROF_TIMER cntRedraw("view-redraw-rects");
244
245 bool isDirty = false;
246
247 cntTotal.Start();
248
249 try
250 {
251 cntUpd.Start();
252
253 try
254 {
255 m_view->UpdateItems();
256 }
257 catch( std::out_of_range& err )
258 {
259 // Don't do anything here but don't fail
260 // This can happen when we don't catch `at()` calls
261 wxLogTrace( traceDrawPanel, wxS( "Out of Range error: %s" ), err.what() );
262 }
263
264 cntUpd.Stop();
265
266 VECTOR2D cursorPos = m_viewControls->GetCursorPosition();
267 bool viewDirty = m_view->IsDirty();
268 bool cursorMoved = ( cursorPos != m_lastCursorPosition );
269
270 // Skip the entire GL cycle when nothing has changed. The front buffer
271 // still shows the previous frame so there is nothing to redraw.
272 if( !viewDirty && !cursorMoved )
273 {
274 m_lastRepaintEnd = wxGetLocalTimeMillis();
275 return true;
276 }
277
278 m_lastCursorPosition = cursorPos;
279
280 // GAL_DRAWING_CONTEXT can throw in the dtor, so we need to scope
281 // the full lifetime inside the try block
282 {
283 cntCtx.Start();
285 cntCtx.Stop();
286
287 if( m_view->IsTargetDirty( KIGFX::TARGET_OVERLAY )
288 && !m_gal->HasTarget( KIGFX::TARGET_OVERLAY ) )
289 {
290 m_view->MarkDirty();
291 }
292
293 m_gal->SetClearColor( settings->GetBackgroundColor() );
294 m_gal->SetGridColor( settings->GetGridColor() );
295 m_gal->SetCursorColor( settings->GetCursorColor() );
296
297 // OpenGL double-buffering leaves the back buffer undefined after
298 // SwapBuffers, so a full clear is always required before compositing.
299 // Cairo only needs to clear when NONCACHED content changed.
301 m_gal->ClearScreen();
302
303 if( m_view->IsDirty() )
304 {
305 if( m_backend != GAL_TYPE_OPENGL // Already called in opengl
306 && m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) )
307 {
308 m_gal->ClearScreen();
309 }
310
311 m_view->ClearTargets();
312
313 // Grid has to be redrawn only when the NONCACHED target is redrawn
314 if( m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) )
315 m_gal->DrawGrid();
316
317 cntRedraw.Start();
318 m_view->Redraw();
319 cntRedraw.Stop();
320 isDirty = true;
321 }
322
323 m_gal->DrawCursor( cursorPos );
324
325 cntCtxDestroy.Start();
326 }
327
328 // ctx goes out of scope here so destructor would be called
329 cntCtxDestroy.Stop();
330 }
331 catch( std::exception& err )
332 {
333 if( GAL_FALLBACK != m_backend )
334 {
336
338 _( "Could not use OpenGL, falling back to software rendering" ),
339 wxString( err.what() ) );
340
341 StartDrawing();
342 }
343 else
344 {
345 // We're well and truly banjaxed if we get here without a fallback.
346 DisplayErrorMessage( m_parent, _( "Graphics error" ), wxString( err.what() ) );
347
348 StopDrawing();
349 }
350 }
351
352 if( isDirty )
353 {
354 KI_TRACE( traceGalProfile, "View timing: %s %s %s %s %s\n",
355 cntTotal.to_string(),
356 cntUpd.to_string(),
357 cntRedraw.to_string(),
358 cntCtx.to_string(),
359 cntCtxDestroy.to_string()
360 );
361 }
362
363 m_lastRepaintEnd = wxGetLocalTimeMillis();
364
365 return true;
366}
367
368
369void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent )
370{
371 // If we get a second wx update call before the first finishes, don't crash
372 if( m_gal->IsContextLocked() )
373 return;
374
376 wxSize clientSize = GetClientSize();
377 WX_INFOBAR* infobar = GetParentEDAFrame() ? GetParentEDAFrame()->GetInfoBar() : nullptr;
378
379 if( ToVECTOR2I( clientSize ) == m_gal->GetScreenPixelSize() )
380 return;
381
382 // Note: ( +1, +1 ) prevents an ugly black line on right and bottom on Mac
383 clientSize.x = std::max( 10, clientSize.x + 1 );
384 clientSize.y = std::max( 10, clientSize.y + 1 );
385
386 VECTOR2D bottom( 0, 0 );
387
388 if( m_view )
389 bottom = m_view->ToWorld( m_gal->GetScreenPixelSize(), true );
390
391 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
392
393 if( m_view )
394 {
395 if( infobar && infobar->IsLocked() )
396 {
397 VECTOR2D halfScreen( std::ceil( 0.5 * clientSize.x ), std::ceil( 0.5 * clientSize.y ) );
398 m_view->SetCenter( bottom - m_view->ToWorld( halfScreen, false ) );
399 }
400
401 m_view->MarkTargetDirty( KIGFX::TARGET_CACHED );
402 m_view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
403 }
404}
405
406
411
412
413void EDA_DRAW_PANEL_GAL::Refresh( bool aEraseBackground, const wxRect* aRect )
414{
415 wxLongLong now = wxGetLocalTimeMillis();
416 wxLongLong delta = now - m_lastRepaintEnd;
417
418 // When vsync is available the driver throttles SwapBuffers, so we only need
419 // a small guard to avoid queueing work faster than the GPU can consume it.
420 // Without vsync, enforce a 60 FPS ceiling to prevent saturating the GPU.
421 int minPeriodMs = 3;
422
423 if( m_gal && m_gal->IsInitialized() && m_gal->GetSwapInterval() == 0 )
424 minPeriodMs = 16;
425
426 if( delta >= minPeriodMs )
427 {
428 if( !DoRePaint() )
430 }
431 else if( !m_refreshTimer.IsRunning() )
432 {
433 m_refreshTimer.StartOnce( ( minPeriodMs - delta ).GetValue() );
434 }
435}
436
437
439{
440 if( !m_drawingEnabled )
441 {
442 if( m_gal && m_gal->IsInitialized() )
443 {
444 Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr,
445 this );
446
447 Connect( wxEVT_IDLE, wxIdleEventHandler( EDA_DRAW_PANEL_GAL::onIdle ), nullptr, this );
448
449 m_drawingEnabled = true;
450 }
451 else
452 {
453 // Try again soon
454 m_refreshTimer.StartOnce( 100 );
455 return;
456 }
457 }
458
459 DoRePaint();
460}
461
462
464{
465 m_eventDispatcher = aEventDispatcher;
466}
467
468
470{
471 // Start querying GAL if it is ready
472 m_refreshTimer.StartOnce( 100 );
473}
474
475
477{
478 m_refreshTimer.Stop();
479 m_drawingEnabled = false;
480
481 Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr, this );
482
483 Disconnect( wxEVT_IDLE, wxIdleEventHandler( EDA_DRAW_PANEL_GAL::onIdle ), nullptr, this );
484}
485
486
488{
489 // Set display settings for high contrast mode
490 KIGFX::RENDER_SETTINGS* rSettings = m_view->GetPainter()->GetSettings();
491
492 SetTopLayer( aLayer );
493
494 rSettings->ClearHighContrastLayers();
495 rSettings->SetLayerIsHighContrast( aLayer );
496
497 m_view->UpdateAllLayersColor();
498}
499
500
502{
503 m_view->ClearTopLayers();
504 m_view->SetTopLayer( aLayer );
505 m_view->UpdateAllLayersOrder();
506}
507
508
510{
511 // Do not do anything if the currently used GAL is correct
512 if( aGalType == m_backend && m_gal != nullptr )
513 return true;
514
515 VECTOR2D grid_size = m_gal ? m_gal->GetGridSize() : VECTOR2D();
516 bool grid_visibility = m_gal ? m_gal->GetGridVisibility() : true;
517 bool result = true; // assume everything will be fine
518
519 // Prevent refreshing canvas during backend switch
520 StopDrawing();
521
522 KIGFX::GAL* new_gal = nullptr;
523
524 try
525 {
526 switch( aGalType )
527 {
528 case GAL_TYPE_OPENGL:
529 {
530 wxString errormsg = KIGFX::OPENGL_GAL::CheckFeatures( m_options );
531
532 if( errormsg.empty() )
533 {
534 new_gal = new KIGFX::OPENGL_GAL( GetVcSettings(), m_options, this, this, this );
535 }
536 else
537 {
538 if( GAL_FALLBACK != aGalType )
539 {
540 aGalType = GAL_FALLBACK;
542 m_parent,
543 _( "Could not use OpenGL, falling back to software rendering" ),
544 errormsg );
545 new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this );
546 }
547 else
548 {
549 // We're well and truly banjaxed if we get here without a fallback.
550 DisplayInfoMessage( m_parent, _( "Could not use OpenGL" ), errormsg );
551 }
552 }
553
554 break;
555 }
556
557 case GAL_TYPE_CAIRO:
558 new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this );
559 break;
560
561 default:
562 wxASSERT( false );
564 // warn about unhandled GAL canvas type, but continue with the fallback option
565
566 case GAL_TYPE_NONE:
567 // KIGFX::GAL is a stub - it actually does cannot display anything,
568 // but prevents code relying on GAL canvas existence from crashing
569 new_gal = new KIGFX::GAL( m_options );
570 break;
571 }
572 }
573 catch( std::runtime_error& err )
574 {
575 // Create a dummy GAL
576 new_gal = new KIGFX::GAL( m_options );
577 aGalType = GAL_TYPE_NONE;
578 DisplayErrorMessage( m_parent, _( "Error switching GAL backend" ), wxString( err.what() ) );
579 result = false;
580 }
581
582 // trigger update of the gal options in case they differ from the defaults
583 m_options.NotifyChanged();
584
585 delete m_gal;
586 m_gal = new_gal;
587
588 wxSize clientSize = GetClientSize();
589 clientSize.x = std::max( 10, clientSize.x );
590 clientSize.y = std::max( 10, clientSize.y );
591 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
592
593 if( grid_size.x > 0 && grid_size.y > 0 )
594 m_gal->SetGridSize( grid_size );
595
596 m_gal->SetGridVisibility( grid_visibility );
597
598 // Make sure the cursor is set on the new canvas
600
601 if( m_painter )
602 m_painter->SetGAL( m_gal );
603
604 if( m_view )
605 {
606 m_view->SetGAL( m_gal );
607 // Note: OpenGL requires reverse draw order when draw priority is enabled
608 m_view->ReverseDrawOrder( aGalType == GAL_TYPE_OPENGL );
609 }
610
611 m_backend = aGalType;
612
613 return result;
614}
615
616
617void EDA_DRAW_PANEL_GAL::OnEvent( wxEvent& aEvent )
618{
619 bool shouldSetFocus = m_lostFocus && m_stealsFocus
620 && !KIUI::IsInputControlFocused() // Don't steal from input controls
621 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
622 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
623
624 if( shouldSetFocus )
625 SetFocus();
626
627 if( !m_eventDispatcher )
628 aEvent.Skip();
629 else
630 m_eventDispatcher->DispatchWxEvent( aEvent );
631
632 Refresh();
633}
634
635
636void EDA_DRAW_PANEL_GAL::onEnter( wxMouseEvent& aEvent )
637{
638 bool shouldSetFocus = m_stealsFocus
639 && !KIUI::IsInputControlFocused() // Don't steal from input controls
640 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
641 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
642
643 // Getting focus is necessary in order to receive key events properly
644 if( shouldSetFocus )
645 SetFocus();
646
647 aEvent.Skip();
648}
649
650
651void EDA_DRAW_PANEL_GAL::onLostFocus( wxFocusEvent& aEvent )
652{
653 m_lostFocus = true;
654
655 m_viewControls->CancelDrag();
656
657 // Reset the tool dispatcher's button state when focus is lost. This prevents
658 // the dispatcher from thinking the button is still pressed when focus returns,
659 // which can cause selection and drag operations to stop working.
661 m_eventDispatcher->ResetState();
662
663 aEvent.Skip();
664}
665
666
667void EDA_DRAW_PANEL_GAL::onIdle( wxIdleEvent& aEvent )
668{
670 {
671 m_needIdleRefresh = false;
672 Refresh();
673 }
674
675 aEvent.Skip();
676}
677
678
679void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent )
680{
681 ForceRefresh();
682}
683
684
685void EDA_DRAW_PANEL_GAL::onShowEvent( wxShowEvent& aEvent )
686{
687 if( m_gal && m_gal->IsInitialized() && m_gal->IsVisible() )
688 {
689 OnShow();
690 }
691}
692
693
695{
696 if( !m_gal )
697 return;
698
699 DPI_SCALING_COMMON dpi( nullptr, m_parent );
700
701 bool hidpi = false;
702
703 // Cursor scaling factor cannot be set for a wxCursor on GTK and OSX (at least before wx 3.3),
704 // resulting in 4x rendered size on 2x window scale.
705 // MSW renders the bitmap as-is, without scaling, so this works here.
706#ifdef __WXMSW__
707 hidpi = dpi.GetContentScaleFactor() >= 2.0;
708#endif
709
710 m_gal->SetNativeCursorStyle( aCursor, hidpi );
711}
712
713
714std::shared_ptr<KIGFX::VIEW_OVERLAY> EDA_DRAW_PANEL_GAL::DebugOverlay()
715{
716 if( !m_debugOverlay )
717 {
718 m_debugOverlay.reset( new KIGFX::VIEW_OVERLAY() );
719 m_view->Add( m_debugOverlay.get() );
720 }
721
722 return m_debugOverlay;
723}
724
725
727{
728 if( m_debugOverlay )
729 {
730 m_view->Remove( m_debugOverlay.get() );
731 m_debugOverlay = nullptr;
732 }
733}
734
735
737{
739
740 KIGFX::VC_SETTINGS vcSettings;
741 vcSettings.m_warpCursor = cfg->m_Input.center_on_zoom;
743 vcSettings.m_autoPanSettingEnabled = cfg->m_Input.auto_pan;
745 vcSettings.m_horizontalPan = cfg->m_Input.horizontal_pan;
747 vcSettings.m_zoomSpeed = cfg->m_Input.zoom_speed;
748 vcSettings.m_zoomSpeedAuto = cfg->m_Input.zoom_speed_auto;
753 vcSettings.m_dragLeft = cfg->m_Input.drag_left;
754 vcSettings.m_dragMiddle = cfg->m_Input.drag_middle;
755 vcSettings.m_dragRight = cfg->m_Input.drag_right;
758
759 return vcSettings;
760}
BASE_SCREEN class implementation.
VECTOR2D m_ScrollCenter
Current scroll center point in logical units.
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetContentScaleFactor() const override
Get the content scale factor, which may be different from the scale factor on some platforms.
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.
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.
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 onIdle(wxIdleEvent &aEvent)
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void onEnter(wxMouseEvent &aEvent)
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.
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.
void onShowEvent(wxShowEvent &aEvent)
GAL_TYPE m_backend
Currently used GAL.
VECTOR2D m_lastCursorPosition
Last cursor position sent to GAL for drawing.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
Abstract interface for drawing on a 2D-surface.
OpenGL implementation of the Graphics Abstraction Layer.
Definition opengl_gal.h:71
static wxString CheckFeatures(GAL_DISPLAY_OPTIONS &aOptions)
Checks OpenGL features.
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.
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
Definition view.h:347
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:541
A small class to help profiling.
Definition profile.h:49
void Stop()
Save the time when this function was called, and set the counter stane to stop.
Definition profile.h:88
void Start()
Start or restart the counter.
Definition profile.h:77
std::string to_string()
Definition profile.h:155
RAII class that sets an value at construction and resets it to the original value at destruction.
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:77
bool IsLocked()
Returns true if the infobar is being updated.
Definition wx_infobar.h:207
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition confirm.cpp:230
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:202
This file is part of the common library.
KICURSOR
Definition cursors.h:44
@ ARROW
Definition cursors.h:46
#define _(s)
static const wxChar traceDrawPanel[]
Flag to enable drawing panel debugging output.
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:38
@ TARGET_CACHED
Main rendering target (cached)
Definition definitions.h:37
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition definitions.h:39
void SetOverlayScrolling(const wxWindow *aWindow, bool overlay)
Used to set overlay/non-overlay scrolling mode in a window.
Definition wxgtk/ui.cpp:288
void ImmControl(wxWindow *aWindow, bool aEnable)
Configures the IME mode of a given control handle.
Definition wxgtk/ui.cpp:405
void ImeNotifyCancelComposition(wxWindow *aWindow)
Asks the IME to cancel.
Definition wxgtk/ui.cpp:410
bool IsWindowActive(wxWindow *aWindow)
Check to see if the given window is the currently active window (e.g.
Definition wxgtk/ui.cpp:147
KICOMMON_API bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
KICOMMON_API bool IsModalDialogFocused()
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
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.
MOUSE_DRAG_ACTION m_dragLeft
bool m_horizontalPan
Enable horizontal panning with the horizontal scroll/trackpad input.
bool m_scrollReversePanH
Whether to invert the scroll wheel movement for horizontal pan.
bool m_autoPanSettingEnabled
Flag for turning on autopanning.
bool m_focusFollowSchPcb
Flag for automatic focus switching between Schematic and PCB editors.
float m_autoPanAcceleration
How fast does panning accelerate when approaching the window boundary.
MOUSE_DRAG_ACTION m_dragMiddle
int m_zoomSpeed
Zoom speed for the non-accelerating zoom controller.
int m_scrollModifierZoom
What modifier key to enable zoom with the (vertical) scroll wheel.
int m_scrollModifierPanH
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
bool m_warpCursor
If the cursor is allowed to be warped.
MOUSE_DRAG_ACTION m_dragRight
bool m_scrollReverseZoom
Whether to invert the scroll wheel movement for zoom.
int m_motionPanModifier
What modifier key pans the view when the mouse moves with it held.
bool m_zoomAcceleration
Enable the accelerating zoom controller.
bool m_zoomSpeedAuto
When true, ignore zoom_speed and pick a platform-specific default.
int m_scrollModifierPanV
What modifier key to enable vertical with the (vertical) scroll wheel.
wxString result
Test unit parsing edge cases and error handling.
int delta
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
VECTOR2< double > VECTOR2D
Definition vector2d.h:694
VECTOR2I ToVECTOR2I(const wxSize &aSize)
Definition vector2wx.h:30
WX_VIEW_CONTROLS class definition.