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, 2024 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 ),
74 m_lastRepaintStart( 0 ),
75 m_lastRepaintEnd( 0 ),
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 ),
83 m_backend( GAL_TYPE_NONE ),
84 m_options( aOptions ),
85 m_eventDispatcher( nullptr ),
86 m_lostFocus( false ),
87 m_stealsFocus( true ),
88 m_statusPopup( nullptr )
89{
90 m_PaintEventCounter = std::make_unique<PROF_COUNTER>( "Draw panel paint events" );
91
92 SetLayoutDirection( wxLayout_LeftToRight );
93
94 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_parent );
95
96 // If we're in a dialog, we have to go looking for our parent frame
97 if( !m_edaFrame )
98 {
99 wxWindow* ancestor = aParentWindow->GetParent();
100
101 while( ancestor && !dynamic_cast<EDA_DRAW_FRAME*>( ancestor ) )
102 ancestor = ancestor->GetParent();
103
104 if( ancestor )
105 m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( ancestor );
106 }
107
108 SwitchBackend( aGalType );
109 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
110
111 if( Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
112 {
113 ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
114 }
115 else
116 {
117 ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
118 }
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 // Set up timer to execute OnShow() method when the window appears on the screen
168 m_onShowTimer.SetOwner( this );
169 Connect( m_onShowTimer.GetId(), wxEVT_TIMER,
170 wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onShowTimer ), nullptr, this );
171 m_onShowTimer.Start( 10 );
172}
173
174
176{
177 StopDrawing();
178
179 wxASSERT( !m_drawing );
180
181 delete m_viewControls;
182 delete m_view;
183 delete m_gal;
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();
198}
199
200
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() )
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 )
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 cntUpd.Start();
253
254 try
255 {
257 }
258 catch( std::out_of_range& err )
259 {
260 // Don't do anything here but don't fail
261 // This can happen when we don't catch `at()` calls
262 wxLogTrace( traceDrawPanel, wxS( "Out of Range error: %s" ), err.what() );
263 }
264
265 cntUpd.Stop();
266
267 // GAL_DRAWING_CONTEXT can throw in the dtor, so we need to scope
268 // the full lifetime inside the try block
269 {
270 cntCtx.Start();
272 cntCtx.Stop();
273
276 {
277 m_view->MarkDirty();
278 }
279
280 m_gal->SetClearColor( settings->GetBackgroundColor() );
281 m_gal->SetGridColor( settings->GetGridColor() );
282 m_gal->SetCursorColor( settings->GetCursorColor() );
283
284 // TODO: find why ClearScreen() must be called here in opengl mode
285 // and only if m_view->IsDirty() in Cairo mode to avoid display artifacts
286 // when moving the mouse cursor
289
290 if( m_view->IsDirty() )
291 {
292 if( m_backend != GAL_TYPE_OPENGL // Already called in opengl
294 {
296 }
297
299
300 // Grid has to be redrawn only when the NONCACHED target is redrawn
302 m_gal->DrawGrid();
303
304 cntRedraw.Start();
305 m_view->Redraw();
306 cntRedraw.Stop();
307 isDirty = true;
308 }
309
311
312 cntCtxDestroy.Start();
313 }
314
315 // ctx goes out of scope here so destructor would be called
316 cntCtxDestroy.Stop();
317 }
318 catch( std::exception& err )
319 {
320 if( GAL_FALLBACK != m_backend )
321 {
323
325 _( "Could not use OpenGL, falling back to software rendering" ),
326 wxString( err.what() ) );
327
328 StartDrawing();
329 }
330 else
331 {
332 // We're well and truly banjaxed if we get here without a fallback.
333 DisplayErrorMessage( m_parent, _( "Graphics error" ), wxString( err.what() ) );
334
335 StopDrawing();
336 }
337 }
338
339 if( isDirty )
340 {
341 KI_TRACE( traceGalProfile, "View timing: %s %s %s %s %s\n",
342 cntTotal.to_string(),
343 cntUpd.to_string(),
344 cntRedraw.to_string(),
345 cntCtx.to_string(),
346 cntCtxDestroy.to_string()
347 );
348 }
349
350 m_lastRepaintEnd = wxGetLocalTimeMillis();
351
352 return true;
353}
354
355
356void EDA_DRAW_PANEL_GAL::onSize( wxSizeEvent& aEvent )
357{
358 // If we get a second wx update call before the first finishes, don't crash
359 if( m_gal->IsContextLocked() )
360 return;
361
363 wxSize clientSize = GetClientSize();
364 WX_INFOBAR* infobar = GetParentEDAFrame() ? GetParentEDAFrame()->GetInfoBar() : nullptr;
365
366 if( ToVECTOR2I( clientSize ) == m_gal->GetScreenPixelSize() )
367 return;
368
369 // Note: ( +1, +1 ) prevents an ugly black line on right and bottom on Mac
370 clientSize.x = std::max( 10, clientSize.x + 1 );
371 clientSize.y = std::max( 10, clientSize.y + 1 );
372
373 VECTOR2D bottom( 0, 0 );
374
375 if( m_view )
376 bottom = m_view->ToWorld( m_gal->GetScreenPixelSize(), true );
377
378 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
379
380 if( m_view )
381 {
382 if( infobar && infobar->IsLocked() )
383 {
384 VECTOR2D halfScreen( std::ceil( 0.5 * clientSize.x ), std::ceil( 0.5 * clientSize.y ) );
385 m_view->SetCenter( bottom - m_view->ToWorld( halfScreen, false ) );
386 }
387
390 }
391}
392
393
394void EDA_DRAW_PANEL_GAL::Refresh( bool aEraseBackground, const wxRect* aRect )
395{
396 if( !DoRePaint() )
397 m_needIdleRefresh = true;
398}
399
400
402{
403 if( !m_drawingEnabled )
404 {
405 if( m_gal && m_gal->IsInitialized() )
406 {
407 Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr,
408 this );
409
410 Connect( wxEVT_IDLE, wxIdleEventHandler( EDA_DRAW_PANEL_GAL::onIdle ), nullptr, this );
411
412 m_drawingEnabled = true;
413 }
414 else
415 {
416 // Try again soon
417 m_refreshTimer.StartOnce( 100 );
418 return;
419 }
420 }
421
422 DoRePaint();
423}
424
425
427{
428 m_eventDispatcher = aEventDispatcher;
429}
430
431
433{
434 // Start querying GAL if it is ready
435 m_refreshTimer.StartOnce( 100 );
436}
437
438
440{
441 m_refreshTimer.Stop();
442 m_drawingEnabled = false;
443
444 Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr, this );
445
446 Disconnect( wxEVT_IDLE, wxIdleEventHandler( EDA_DRAW_PANEL_GAL::onIdle ), nullptr, this );
447}
448
449
451{
452 // Set display settings for high contrast mode
454
455 SetTopLayer( aLayer );
456
457 rSettings->ClearHighContrastLayers();
458 rSettings->SetLayerIsHighContrast( aLayer );
459
461}
462
463
465{
467 m_view->SetTopLayer( aLayer );
469}
470
471
473{
474 // Do not do anything if the currently used GAL is correct
475 if( aGalType == m_backend && m_gal != nullptr )
476 return true;
477
478 VECTOR2D grid_size = m_gal ? m_gal->GetGridSize() : VECTOR2D();
479 bool grid_visibility = m_gal ? m_gal->GetGridVisibility() : true;
480 bool result = true; // assume everything will be fine
481
482 // Prevent refreshing canvas during backend switch
483 StopDrawing();
484
485 KIGFX::GAL* new_gal = nullptr;
486
487 try
488 {
489 switch( aGalType )
490 {
491 case GAL_TYPE_OPENGL:
492 {
493 wxString errormsg = KIGFX::OPENGL_GAL::CheckFeatures( m_options );
494
495 if( errormsg.empty() )
496 {
497 new_gal = new KIGFX::OPENGL_GAL( GetVcSettings(), m_options, this, this, this );
498 }
499 else
500 {
501 if( GAL_FALLBACK != aGalType )
502 {
503 aGalType = GAL_FALLBACK;
505 m_parent,
506 _( "Could not use OpenGL, falling back to software rendering" ),
507 errormsg );
508 new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this );
509 }
510 else
511 {
512 // We're well and truly banjaxed if we get here without a fallback.
513 DisplayInfoMessage( m_parent, _( "Could not use OpenGL" ), errormsg );
514 }
515 }
516 break;
517 }
518
519 case GAL_TYPE_CAIRO: new_gal = new KIGFX::CAIRO_GAL( m_options, this, this, this ); break;
520
521 default:
522 wxASSERT( false );
524 // warn about unhandled GAL canvas type, but continue with the fallback option
525
526 case GAL_TYPE_NONE:
527 // KIGFX::GAL is a stub - it actually does cannot display anything,
528 // but prevents code relying on GAL canvas existence from crashing
529 new_gal = new KIGFX::GAL( m_options );
530 break;
531 }
532 }
533 catch( std::runtime_error& err )
534 {
535 // Create a dummy GAL
536 new_gal = new KIGFX::GAL( m_options );
537 aGalType = GAL_TYPE_NONE;
538 DisplayError( m_parent, wxString( err.what() ) );
539 result = false;
540 }
541
542 // trigger update of the gal options in case they differ from the defaults
544
545 delete m_gal;
546 m_gal = new_gal;
547
548 wxSize clientSize = GetClientSize();
549 clientSize.x = std::max( 10, clientSize.x );
550 clientSize.y = std::max( 10, clientSize.y );
551 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
552
553 if( grid_size.x > 0 && grid_size.y > 0 )
554 m_gal->SetGridSize( grid_size );
555
556 m_gal->SetGridVisibility( grid_visibility );
557
558 // Make sure the cursor is set on the new canvas
559 SetCurrentCursor( KICURSOR::ARROW );
560
561 if( m_painter )
562 m_painter->SetGAL( m_gal );
563
564 if( m_view )
565 {
566 m_view->SetGAL( m_gal );
567 // Note: OpenGL requires reverse draw order when draw priority is enabled
569 }
570
571 m_backend = aGalType;
572
573 return result;
574}
575
576
577void EDA_DRAW_PANEL_GAL::OnEvent( wxEvent& aEvent )
578{
579 bool shouldSetFocus = m_lostFocus && m_stealsFocus
580 && !KIUI::IsInputControlFocused() // Don't steal from input controls
581 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
582 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
583
584 if( shouldSetFocus )
585 SetFocus();
586
587 if( !m_eventDispatcher )
588 aEvent.Skip();
589 else
591
592 // Give events time to process, based on last render duration
593 wxLongLong endDelta = wxGetLocalTimeMillis() - m_lastRepaintEnd;
594 long long timeLimit = ( m_lastRepaintEnd - m_lastRepaintStart ).GetValue() / 5;
595
596 timeLimit = std::clamp( timeLimit, 3LL, 150LL );
597
598 if( endDelta > timeLimit )
599 Refresh();
600 else
601 m_needIdleRefresh = true;
602}
603
604
605void EDA_DRAW_PANEL_GAL::onEnter( wxMouseEvent& aEvent )
606{
607 bool shouldSetFocus = m_stealsFocus
608 && !KIUI::IsInputControlFocused() // Don't steal from input controls
609 && !KIUI::IsModalDialogFocused() // Don't steal from dialogs
610 && KIPLATFORM::UI::IsWindowActive( m_edaFrame ); // Don't steal from other windows
611
612 // Getting focus is necessary in order to receive key events properly
613 if( shouldSetFocus )
614 SetFocus();
615
616 aEvent.Skip();
617}
618
619
620void EDA_DRAW_PANEL_GAL::onLostFocus( wxFocusEvent& aEvent )
621{
622 m_lostFocus = true;
623
625
626 aEvent.Skip();
627}
628
629
630void EDA_DRAW_PANEL_GAL::onIdle( wxIdleEvent& aEvent )
631{
633 {
634 m_needIdleRefresh = false;
635 Refresh();
636 }
637
638 aEvent.Skip();
639}
640
641
642void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent )
643{
644 ForceRefresh();
645}
646
647
648void EDA_DRAW_PANEL_GAL::onShowTimer( wxTimerEvent& aEvent )
649{
650 if( m_gal && m_gal->IsInitialized() && m_gal->IsVisible() )
651 {
652 m_onShowTimer.Stop();
653 OnShow();
654 }
655}
656
657
659{
660 if( !m_gal )
661 return;
662
663 DPI_SCALING_COMMON dpi( nullptr, m_parent );
664
665 bool hidpi = false;
666
667 // Cursor scaling factor cannot be set for a wxCursor on GTK and OSX (at least before wx 3.3),
668 // resulting in 4x rendered size on 2x window scale.
669 // MSW renders the bitmap as-is, without scaling, so this works here.
670#ifdef __WXMSW__
671 hidpi = dpi.GetContentScaleFactor() >= 2.0;
672#endif
673
674 m_gal->SetNativeCursorStyle( aCursor, hidpi );
675}
676
677
678std::shared_ptr<KIGFX::VIEW_OVERLAY> EDA_DRAW_PANEL_GAL::DebugOverlay()
679{
680 if( !m_debugOverlay )
681 {
682 m_debugOverlay.reset( new KIGFX::VIEW_OVERLAY() );
683 m_view->Add( m_debugOverlay.get() );
684 }
685
686 return m_debugOverlay;
687}
688
689
691{
692 if( m_debugOverlay )
693 {
694 m_view->Remove( m_debugOverlay.get() );
695 m_debugOverlay = nullptr;
696 }
697}
698
699
701{
703
704 KIGFX::VC_SETTINGS vcSettings;
705 vcSettings.m_warpCursor = cfg->m_Input.center_on_zoom;
707 vcSettings.m_autoPanSettingEnabled = cfg->m_Input.auto_pan;
709 vcSettings.m_horizontalPan = cfg->m_Input.horizontal_pan;
711 vcSettings.m_zoomSpeed = cfg->m_Input.zoom_speed;
712 vcSettings.m_zoomSpeedAuto = cfg->m_Input.zoom_speed_auto;
716 vcSettings.m_dragLeft = cfg->m_Input.drag_left;
717 vcSettings.m_dragMiddle = cfg->m_Input.drag_middle;
718 vcSettings.m_dragRight = cfg->m_Input.drag_right;
720
721 return vcSettings;
722}
BASE_SCREEN class implementation.
VECTOR2D m_ScrollCenter
Current scroll center point in logical units.
Definition: base_screen.h:100
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.
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 SetNativeCursorStyle(KICURSOR aCursor, bool aHiDPI)
Set the cursor in the native panel.
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.
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:464
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:897
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:1139
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition: view.cpp:766
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:1158
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:882
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:1427
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:830
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
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:678
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.
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:170
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:222
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
KICURSOR
Definition: cursors.h:34
#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: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
void ImeNotifyCancelComposition(wxWindow *aWindow)
Asks the IME to cancel.
Definition: gtk/ui.cpp:324
bool IsWindowActive(wxWindow *aWindow)
Check to see if the given window is the currently active window (e.g.
Definition: gtk/ui.cpp:73
KICOMMON_API bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
Definition: ui_common.cpp:263
KICOMMON_API bool IsModalDialogFocused()
Definition: ui_common.cpp:317
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.
Definition: pgm_base.cpp:1059
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.
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:601
VECTOR2I ToVECTOR2I(const wxSize &aSize)
Definition: vector2wx.h:30
WX_VIEW_CONTROLS class definition.