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_glRecoveryAttempted( false ),
88 m_stealsFocus( true ),
89 m_statusPopup( nullptr )
90{
91#ifdef _WIN32
92 // need to fix broken cairo rendering on Windows with wx 3.3
93 SetDoubleBuffered( false );
94#endif
95 m_PaintEventCounter = std::make_unique<PROF_COUNTER>( "Draw panel paint events" );
96
97 if( Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
98 ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
99 else
100 ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
101
102 SetLayoutDirection( wxLayout_LeftToRight );
103
104 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_parent );
105
106 // If we're in a dialog, we have to go looking for our parent frame
107 if( !m_edaFrame )
108 {
109 wxWindow* ancestor = aParentWindow->GetParent();
110
111 while( ancestor && !dynamic_cast<EDA_DRAW_FRAME*>( ancestor ) )
112 ancestor = ancestor->GetParent();
113
114 if( ancestor )
115 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( ancestor );
116 }
117
118 SwitchBackend( aGalType );
119 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
120
121 EnableScrolling( false, false ); // otherwise Zoom Auto disables GAL canvas
122 KIPLATFORM::UI::SetOverlayScrolling( this, false ); // Prevent excessive repaint on GTK
123 KIPLATFORM::UI::ImmControl( this, false ); // Ensure our panel can't suck in IME events
124
125 Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), nullptr, this );
126 Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), nullptr,
127 this );
128 Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), nullptr,
129 this );
130
131 const wxEventType events[] = {
132 // Binding both EVT_CHAR and EVT_CHAR_HOOK ensures that all key events,
133 // especially special key like arrow keys, are handled by the GAL event dispatcher,
134 // and not sent to GUI without filtering, because they have a default action (scroll)
135 // that must not be called.
136 wxEVT_LEFT_UP,
137 wxEVT_LEFT_DOWN,
138 wxEVT_LEFT_DCLICK,
139 wxEVT_RIGHT_UP,
140 wxEVT_RIGHT_DOWN,
141 wxEVT_RIGHT_DCLICK,
142 wxEVT_MIDDLE_UP,
143 wxEVT_MIDDLE_DOWN,
144 wxEVT_MIDDLE_DCLICK,
145 wxEVT_AUX1_UP,
146 wxEVT_AUX1_DOWN,
147 wxEVT_AUX1_DCLICK,
148 wxEVT_AUX2_UP,
149 wxEVT_AUX2_DOWN,
150 wxEVT_AUX2_DCLICK,
151 wxEVT_MOTION,
152 wxEVT_MOUSEWHEEL,
153 wxEVT_CHAR,
154 wxEVT_CHAR_HOOK,
155 wxEVT_MAGNIFY,
157 };
158
159 for( wxEventType eventType : events )
160 Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::OnEvent ), nullptr,
162
163 // Set up timer to detect when drawing starts
164 m_refreshTimer.SetOwner( this );
165 Connect( m_refreshTimer.GetId(), wxEVT_TIMER,
166 wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), nullptr, this );
167
168 Connect( wxEVT_SHOW, wxShowEventHandler( EDA_DRAW_PANEL_GAL::onShowEvent ), nullptr, this );
169}
170
171
173{
174 // Ensure EDA_DRAW_PANEL_GAL::onShowEvent is not fired during Dtor process
175 Disconnect( wxEVT_SHOW, wxShowEventHandler( EDA_DRAW_PANEL_GAL::onShowEvent ) );
176 StopDrawing();
177
178 wxASSERT( !m_drawing );
179
180 delete m_viewControls;
181 delete m_view;
182 delete m_gal;
183 m_gal = nullptr; // Ensure OnShow is not called
184}
185
186
188{
190 wxScrolledCanvas::SetFocus();
191 m_lostFocus = false;
192}
193
194
195void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
196{
197 DoRePaint( false );
198}
199
200
201bool EDA_DRAW_PANEL_GAL::DoRePaint( bool aAllowSkip )
202{
203 if( !m_refreshMutex.try_lock() )
204 return false;
205
206 std::lock_guard<std::mutex> lock( m_refreshMutex, std::adopt_lock );
207
208 if( !m_drawingEnabled )
209 return false;
210
211 if( !m_gal->IsInitialized() || !m_gal->IsVisible() || m_gal->IsContextLocked() )
212 return false;
213
214 if( m_drawing )
215 return false;
216
217 m_lastRepaintStart = wxGetLocalTimeMillis();
218
219 // Repaint the canvas, and fix scrollbar cursors
220 // Usually called by a OnPaint event, but because it does not use a wxPaintDC,
221 // it can be called outside a wxPaintEvent.
222
223 // Update current zoom settings if the canvas is managed by a EDA frame
224 // (i.e. not by a preview panel in a dialog)
225 if( !IsDialogPreview() && GetParentEDAFrame() && GetParentEDAFrame()->GetScreen() )
227
228 if( Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
229 m_viewControls->UpdateScrollbars();
230
231 SCOPED_SET_RESET<bool> drawing( m_drawing, true );
232
233 ( *m_PaintEventCounter )++;
234
235 wxASSERT( m_painter );
236
237 KIGFX::RENDER_SETTINGS* settings =
238 static_cast<KIGFX::RENDER_SETTINGS*>( m_painter->GetSettings() );
239
240 PROF_TIMER cntUpd("view-upd-items");
241 PROF_TIMER cntTotal("view-total");
242 PROF_TIMER cntCtx("view-context-create");
243 PROF_TIMER cntCtxDestroy("view-context-destroy");
244 PROF_TIMER cntRedraw("view-redraw-rects");
245
246 bool isDirty = false;
247
248 cntTotal.Start();
249
250 try
251 {
252 VECTOR2D cursorPos = m_viewControls->GetCursorPosition();
253 bool viewDirty = m_view->IsDirty();
254 bool cursorMoved = ( cursorPos != m_lastCursorPosition );
255 bool hasPendingItemUpdates = m_view->HasPendingItemUpdates();
256
257 // Skip all update work when nothing has changed since the previous frame.
258 // Never skip when responding to a native paint event or explicit ForceRefresh
259 // because the window content may have been invalidated by the OS.
260 if( aAllowSkip && !viewDirty && !cursorMoved && !hasPendingItemUpdates )
261 {
262 m_lastRepaintEnd = wxGetLocalTimeMillis();
263 return true;
264 }
265
266 if( hasPendingItemUpdates )
267 {
268 cntUpd.Start();
269
270 try
271 {
272 m_view->UpdateItems();
273 }
274 catch( std::out_of_range& err )
275 {
276 // Don't do anything here but don't fail
277 // This can happen when we don't catch `at()` calls
278 wxLogTrace( traceDrawPanel, wxS( "Out of Range error: %s" ), err.what() );
279 }
280 catch( std::runtime_error& err )
281 {
282 // Handle GL errors (e.g. glMapBuffer failure) that surface during UpdateItems().
283 // These can occur on macOS under memory pressure when embedding large 3D models.
284 // Log and continue so the outer handler can decide whether to switch backends.
285 wxLogTrace( traceDrawPanel, wxS( "Runtime error during UpdateItems: %s" ),
286 err.what() );
287 throw;
288 }
289
290 cntUpd.Stop();
291 viewDirty = m_view->IsDirty();
292 }
293
294 // After processing item updates, skip the GL cycle when neither the
295 // view targets nor the cursor position have changed.
296 if( aAllowSkip && !viewDirty && !cursorMoved )
297 {
298 m_lastRepaintEnd = wxGetLocalTimeMillis();
299 return true;
300 }
301
302 m_lastCursorPosition = cursorPos;
303
304 // GAL_DRAWING_CONTEXT can throw in the dtor, so we need to scope
305 // the full lifetime inside the try block
306 {
307 cntCtx.Start();
309 cntCtx.Stop();
310
311 if( m_view->IsTargetDirty( KIGFX::TARGET_OVERLAY )
312 && !m_gal->HasTarget( KIGFX::TARGET_OVERLAY ) )
313 {
314 m_view->MarkDirty();
315 }
316
317 m_gal->SetClearColor( settings->GetBackgroundColor() );
318 m_gal->SetGridColor( settings->GetGridColor() );
319 m_gal->SetCursorColor( settings->GetCursorColor() );
320
321 // OpenGL double-buffering leaves the back buffer undefined after
322 // SwapBuffers, so a full clear is always required before compositing.
323 // Cairo only needs to clear when NONCACHED content changed.
325 m_gal->ClearScreen();
326
327 if( m_view->IsDirty() )
328 {
329 if( m_backend != GAL_TYPE_OPENGL // Already called in opengl
330 && m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) )
331 {
332 m_gal->ClearScreen();
333 }
334
335 m_view->ClearTargets();
336
337 // Grid has to be redrawn only when the NONCACHED target is redrawn
338 if( m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) )
339 m_gal->DrawGrid();
340
341 cntRedraw.Start();
342 m_view->Redraw();
343 cntRedraw.Stop();
344 isDirty = true;
345 }
346
347 m_gal->DrawCursor( cursorPos );
348
349 cntCtxDestroy.Start();
350 }
351
352 // ctx goes out of scope here so destructor would be called
353 cntCtxDestroy.Stop();
354
355 // OpenGL frame completed successfully, allow future recovery attempts
356 m_glRecoveryAttempted = false;
357 }
358 catch( std::exception& err )
359 {
360 if( GAL_FALLBACK != m_backend )
361 {
362 // Sleep/wake and GPU resets can invalidate the entire GL context. Try a
363 // full OpenGL reinit once before falling back to software rendering.
365 {
367 GAL_TYPE prevBackend = m_backend;
369
370 if( SwitchBackend( prevBackend ) )
371 {
372 StartDrawing();
373 return true;
374 }
375 }
376
377 m_glRecoveryAttempted = false;
379
381 _( "Could not use OpenGL, falling back to software rendering" ),
382 wxString( err.what() ) );
383
384 StartDrawing();
385 }
386 else
387 {
388 // We're well and truly banjaxed if we get here without a fallback.
389 DisplayErrorMessage( m_parent, _( "Graphics error" ), wxString( err.what() ) );
390
391 StopDrawing();
392 }
393 }
394
395 if( isDirty )
396 {
397 KI_TRACE( traceGalProfile, "View timing: %s %s %s %s %s\n",
398 cntTotal.to_string(),
399 cntUpd.to_string(),
400 cntRedraw.to_string(),
401 cntCtx.to_string(),
402 cntCtxDestroy.to_string()
403 );
404 }
405
406 m_lastRepaintEnd = wxGetLocalTimeMillis();
407
408 return true;
409}
410
411
412void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent )
413{
414 // If we get a second wx update call before the first finishes, don't crash
415 if( m_gal->IsContextLocked() )
416 return;
417
419 wxSize clientSize = GetClientSize();
420 WX_INFOBAR* infobar = GetParentEDAFrame() ? GetParentEDAFrame()->GetInfoBar() : nullptr;
421
422 if( ToVECTOR2I( clientSize ) == m_gal->GetScreenPixelSize() )
423 return;
424
425 // Note: ( +1, +1 ) prevents an ugly black line on right and bottom on Mac
426 clientSize.x = std::max( 10, clientSize.x + 1 );
427 clientSize.y = std::max( 10, clientSize.y + 1 );
428
429 VECTOR2D bottom( 0, 0 );
430
431 if( m_view )
432 bottom = m_view->ToWorld( m_gal->GetScreenPixelSize(), true );
433
434 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
435
436 if( m_view )
437 {
438 if( infobar && infobar->IsLocked() )
439 {
440 VECTOR2D halfScreen( std::ceil( 0.5 * clientSize.x ), std::ceil( 0.5 * clientSize.y ) );
441 m_view->SetCenter( bottom - m_view->ToWorld( halfScreen, false ) );
442 }
443
444 m_view->MarkTargetDirty( KIGFX::TARGET_CACHED );
445 m_view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
446 }
447}
448
449
454
455
456void EDA_DRAW_PANEL_GAL::Refresh( bool aEraseBackground, const wxRect* aRect )
457{
458 wxLongLong now = wxGetLocalTimeMillis();
459 wxLongLong delta = now - m_lastRepaintEnd;
460 bool galInitialized = m_gal && m_gal->IsInitialized();
461
462 // When vsync is available the driver throttles SwapBuffers, so we only need
463 // a small guard to avoid queueing work faster than the GPU can consume it.
464 // Without vsync, enforce a 60 FPS ceiling to prevent saturating the GPU.
465 int minPeriodMs = 3;
466
467 if( galInitialized && m_gal->GetSwapInterval() == 0 )
468 minPeriodMs = 16;
469
470 if( delta >= minPeriodMs )
471 {
472 if( !DoRePaint() )
474 }
475 else if( !m_refreshTimer.IsRunning() )
476 {
477 m_refreshTimer.StartOnce( ( minPeriodMs - delta ).GetValue() );
478 }
479}
480
481
483{
484 if( !m_drawingEnabled )
485 {
486 if( m_gal && m_gal->IsInitialized() )
487 {
488 Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr,
489 this );
490
491 Connect( wxEVT_IDLE, wxIdleEventHandler( EDA_DRAW_PANEL_GAL::onIdle ), nullptr, this );
492
493 m_drawingEnabled = true;
494 }
495 else
496 {
497 // Try again soon
498 m_refreshTimer.StartOnce( 100 );
499 return;
500 }
501 }
502
503 DoRePaint( false );
504}
505
506
508{
509 m_eventDispatcher = aEventDispatcher;
510}
511
512
514{
515 // Start querying GAL if it is ready
516 m_refreshTimer.StartOnce( 100 );
517}
518
519
521{
522 m_refreshTimer.Stop();
523 m_drawingEnabled = false;
524
525 Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr, this );
526
527 Disconnect( wxEVT_IDLE, wxIdleEventHandler( EDA_DRAW_PANEL_GAL::onIdle ), nullptr, this );
528}
529
530
532{
533 // Set display settings for high contrast mode
534 KIGFX::RENDER_SETTINGS* rSettings = m_view->GetPainter()->GetSettings();
535
536 SetTopLayer( aLayer );
537
538 rSettings->ClearHighContrastLayers();
539 rSettings->SetLayerIsHighContrast( aLayer );
540
541 m_view->UpdateAllLayersColor();
542}
543
544
546{
547 m_view->ClearTopLayers();
548 m_view->SetTopLayer( aLayer );
549 m_view->UpdateAllLayersOrder();
550}
551
552
554{
555 // Do not do anything if the currently used GAL is correct
556 if( aGalType == m_backend && m_gal != nullptr )
557 return true;
558
559 VECTOR2D grid_size = m_gal ? m_gal->GetGridSize() : VECTOR2D();
560 bool grid_visibility = m_gal ? m_gal->GetGridVisibility() : true;
561 bool result = true; // assume everything will be fine
562
563 // Prevent refreshing canvas during backend switch
564 StopDrawing();
565
566 KIGFX::GAL* new_gal = nullptr;
567
568 try
569 {
570 switch( aGalType )
571 {
572 case GAL_TYPE_OPENGL:
573 {
574 wxString errormsg = KIGFX::OPENGL_GAL::CheckFeatures( m_options );
575
576 if( errormsg.empty() )
577 {
578 new_gal = new KIGFX::OPENGL_GAL( GetVcSettings(), m_options, this, this, this );
579 }
580 else
581 {
582 if( GAL_FALLBACK != aGalType )
583 {
584 aGalType = GAL_FALLBACK;
586 m_parent,
587 _( "Could not use OpenGL, falling back to software rendering" ),
588 errormsg );
589 new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this );
590 }
591 else
592 {
593 // We're well and truly banjaxed if we get here without a fallback.
594 DisplayInfoMessage( m_parent, _( "Could not use OpenGL" ), errormsg );
595 }
596 }
597
598 break;
599 }
600
601 case GAL_TYPE_CAIRO:
602 new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this );
603 break;
604
605 default:
606 wxASSERT( false );
608 // warn about unhandled GAL canvas type, but continue with the fallback option
609
610 case GAL_TYPE_NONE:
611 // KIGFX::GAL is a stub - it actually does cannot display anything,
612 // but prevents code relying on GAL canvas existence from crashing
613 new_gal = new KIGFX::GAL( m_options );
614 break;
615 }
616 }
617 catch( std::runtime_error& err )
618 {
619 // Create a dummy GAL
620 new_gal = new KIGFX::GAL( m_options );
621 aGalType = GAL_TYPE_NONE;
622 DisplayErrorMessage( m_parent, _( "Error switching GAL backend" ), wxString( err.what() ) );
623 result = false;
624 }
625
626 // trigger update of the gal options in case they differ from the defaults
627 m_options.NotifyChanged();
628
629 delete m_gal;
630 m_gal = new_gal;
631
632 wxSize clientSize = GetClientSize();
633 clientSize.x = std::max( 10, clientSize.x );
634 clientSize.y = std::max( 10, clientSize.y );
635 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
636
637 if( grid_size.x > 0 && grid_size.y > 0 )
638 m_gal->SetGridSize( grid_size );
639
640 m_gal->SetGridVisibility( grid_visibility );
641
642 // Make sure the cursor is set on the new canvas
644
645 if( m_painter )
646 m_painter->SetGAL( m_gal );
647
648 if( m_view )
649 {
650 m_view->SetGAL( m_gal );
651 // Note: OpenGL requires reverse draw order when draw priority is enabled
652 m_view->ReverseDrawOrder( aGalType == GAL_TYPE_OPENGL );
653 }
654
655 m_backend = aGalType;
656
657 return result;
658}
659
660
661void EDA_DRAW_PANEL_GAL::OnEvent( wxEvent& aEvent )
662{
663 bool shouldSetFocus = m_lostFocus && m_stealsFocus
664 && !KIUI::IsInputControlFocused() // Don't steal from input controls
665 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
666 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
667
668 if( shouldSetFocus )
669 SetFocus();
670
671 if( !m_eventDispatcher )
672 aEvent.Skip();
673 else
674 m_eventDispatcher->DispatchWxEvent( aEvent );
675
676 Refresh();
677}
678
679
680void EDA_DRAW_PANEL_GAL::onEnter( wxMouseEvent& aEvent )
681{
682 bool shouldSetFocus = m_stealsFocus
683 && !KIUI::IsInputControlFocused() // Don't steal from input controls
684 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
685 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
686
687 // Getting focus is necessary in order to receive key events properly
688 if( shouldSetFocus )
689 SetFocus();
690
691 aEvent.Skip();
692}
693
694
695void EDA_DRAW_PANEL_GAL::onLostFocus( wxFocusEvent& aEvent )
696{
697 m_lostFocus = true;
698
699 m_viewControls->CancelDrag();
700
701 // Reset the tool dispatcher's button state when focus is lost. This prevents
702 // the dispatcher from thinking the button is still pressed when focus returns,
703 // which can cause selection and drag operations to stop working.
705 m_eventDispatcher->ResetState();
706
707 aEvent.Skip();
708}
709
710
711void EDA_DRAW_PANEL_GAL::onIdle( wxIdleEvent& aEvent )
712{
714 {
715 m_needIdleRefresh = false;
716 Refresh();
717 }
718
719 aEvent.Skip();
720}
721
722
723void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent )
724{
725 ForceRefresh();
726}
727
728
729void EDA_DRAW_PANEL_GAL::onShowEvent( wxShowEvent& aEvent )
730{
731 if( m_gal && m_gal->IsInitialized() && m_gal->IsVisible() )
732 {
733 OnShow();
734 }
735}
736
737
739{
740 if( !m_gal )
741 return;
742
743 DPI_SCALING_COMMON dpi( nullptr, m_parent );
744
745 bool hidpi = false;
746
747 // Cursor scaling factor cannot be set for a wxCursor on GTK and OSX (at least before wx 3.3),
748 // resulting in 4x rendered size on 2x window scale.
749 // MSW renders the bitmap as-is, without scaling, so this works here.
750#ifdef __WXMSW__
751 hidpi = dpi.GetContentScaleFactor() >= 2.0;
752#endif
753
754 m_gal->SetNativeCursorStyle( aCursor, hidpi );
755}
756
757
758std::shared_ptr<KIGFX::VIEW_OVERLAY> EDA_DRAW_PANEL_GAL::DebugOverlay()
759{
760 if( !m_debugOverlay )
761 {
762 m_debugOverlay.reset( new KIGFX::VIEW_OVERLAY() );
763 m_view->Add( m_debugOverlay.get() );
764 }
765
766 return m_debugOverlay;
767}
768
769
771{
772 if( m_debugOverlay )
773 {
774 m_view->Remove( m_debugOverlay.get() );
775 m_debugOverlay = nullptr;
776 }
777}
778
779
781{
783
784 KIGFX::VC_SETTINGS vcSettings;
785 vcSettings.m_warpCursor = cfg->m_Input.center_on_zoom;
787 vcSettings.m_autoPanSettingEnabled = cfg->m_Input.auto_pan;
789 vcSettings.m_horizontalPan = cfg->m_Input.horizontal_pan;
791 vcSettings.m_zoomSpeed = cfg->m_Input.zoom_speed;
792 vcSettings.m_zoomSpeedAuto = cfg->m_Input.zoom_speed_auto;
797 vcSettings.m_dragLeft = cfg->m_Input.drag_left;
798 vcSettings.m_dragMiddle = cfg->m_Input.drag_middle;
799 vcSettings.m_dragRight = cfg->m_Input.drag_right;
802
803 return vcSettings;
804}
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
bool m_glRecoveryAttempted
Set after an OpenGL recovery attempt to prevent infinite retry loops.
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
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.
bool DoRePaint(bool aAllowSkip=true)
Repaint the canvas, and fix scrollbar cursors.
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
bool m_drawingEnabled
Flag that determines if VIEW may use GAL for redrawing the screen.
std::shared_ptr< KIGFX::VIEW_OVERLAY > DebugOverlay()
Create an overlay for rendering debug graphics.
void onShowEvent(wxShowEvent &aEvent)
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:73
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:547
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.