KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_view_controls.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) 2012 Torsten Hueter, torstenhtr <at> gmx.de
5 * Copyright (C) 2013-2015 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * @author Tomasz Wlostowski <[email protected]>
9 * @author Maciej Suminski <[email protected]>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25#include <pgm_base.h>
26#include <core/profile.h>
27#include <view/view.h>
32#include <trace_helpers.h>
34#include <math/util.h> // for KiROUND
36#include <widgets/ui_common.h>
38#include <eda_draw_frame.h>
39#include <kiway.h>
40#include <kiplatform/ui.h>
41#include <wx/log.h>
42#include <wx/utils.h>
43
44#include <cmath>
45
46#ifdef __WXMSW__
47#define USE_MOUSE_CAPTURE
48#endif
49
50#ifdef KICAD_GAL_PROFILE
51#include <trace_helpers.h>
52#endif
53
54using namespace KIGFX;
55
56const wxEventType WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE = wxNewEventType();
57
58
59static std::unique_ptr<ZOOM_CONTROLLER> GetZoomControllerForPlatform( bool aAcceleration )
60{
61#ifdef __WXMAC__
62 // On Apple pointer devices, wheel events occur frequently and with
63 // smaller rotation values. For those devices, let's handle zoom
64 // based on the rotation amount rather than the time difference.
65 return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::MAC_SCALE );
66#elif __WXGTK3__
67 // GTK3 is similar, but the scale constant is smaller
68 return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::GTK3_SCALE );
69#else
70 if( aAcceleration )
71 return std::make_unique<ACCELERATING_ZOOM_CONTROLLER>();
72 else
73 return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::MSW_SCALE );
74#endif
75}
76
77
79 VIEW_CONTROLS( aView ),
80 m_state( IDLE ),
81 m_parentPanel( aParentPanel ),
82 m_dragStartPoint( 0, 0 ),
83 m_panDirection( 0, 0 ),
84 m_scrollScale( 1.0, 1.0 ),
85 m_scrollPos( 0, 0 ),
86 m_zoomStartPoint( 0, 0 ),
87 m_cursorPos( 0, 0 ),
88 m_updateCursor( true ),
89 m_metaPanning( false ),
90 m_metaPanStart( 0, 0 ),
91 m_infinitePanWorks( false ),
93 m_gestureLastPos( 0, 0 )
94{
96
97 m_MotionEventCounter = std::make_unique<PROF_COUNTER>( "Mouse motion events" );
98
99 m_parentPanel->Connect( wxEVT_MOTION,
100 wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), nullptr, this );
101 m_parentPanel->Connect( wxEVT_MAGNIFY,
102 wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), nullptr, this );
103 m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
104 wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), nullptr, this );
105 m_parentPanel->Connect( wxEVT_MIDDLE_UP,
106 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
107 m_parentPanel->Connect( wxEVT_MIDDLE_DOWN,
108 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
109 m_parentPanel->Connect( wxEVT_LEFT_UP,
110 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
111 m_parentPanel->Connect( wxEVT_LEFT_DOWN,
112 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
113 m_parentPanel->Connect( wxEVT_RIGHT_UP,
114 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
115 m_parentPanel->Connect( wxEVT_RIGHT_DOWN,
116 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
117#if defined __WXMSW__
118 m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
119 wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), nullptr, this );
120#endif
121 m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
122 wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), nullptr, this );
123 m_parentPanel->Connect( wxEVT_SCROLLWIN_THUMBTRACK,
124 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
125 m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEUP,
126 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
127 m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEDOWN,
128 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
129
130 m_parentPanel->Connect( wxEVT_SCROLLWIN_BOTTOM,
131 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
132 m_parentPanel->Connect( wxEVT_SCROLLWIN_TOP,
133 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
134 m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEUP,
135 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
136 m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEDOWN,
137 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
138#if defined USE_MOUSE_CAPTURE
139 m_parentPanel->Connect( wxEVT_MOUSE_CAPTURE_LOST,
140 wxMouseEventHandler( WX_VIEW_CONTROLS::onCaptureLost ), nullptr, this );
141#endif
142
143#ifndef __WXOSX__
144 if( m_parentPanel->EnableTouchEvents( wxTOUCH_ZOOM_GESTURE | wxTOUCH_PAN_GESTURES ) )
145 {
146 m_parentPanel->Connect( wxEVT_GESTURE_ZOOM,
147 wxZoomGestureEventHandler( WX_VIEW_CONTROLS::onZoomGesture ),
148 nullptr, this );
149
150 m_parentPanel->Connect( wxEVT_GESTURE_PAN,
151 wxPanGestureEventHandler( WX_VIEW_CONTROLS::onPanGesture ), nullptr,
152 this );
153 }
154#endif
155
156 m_cursorWarped = false;
157
158 m_panTimer.SetOwner( this );
159 Connect( wxEVT_TIMER, wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), nullptr, this );
160
161 m_settings.m_lastKeyboardCursorPositionValid = false;
162 m_settings.m_lastKeyboardCursorPosition = { 0.0, 0.0 };
163 m_settings.m_lastKeyboardCursorCommand = 0;
164}
165
166
168{
169#if defined USE_MOUSE_CAPTURE
170 if( m_parentPanel->HasCapture() )
171 m_parentPanel->ReleaseMouse();
172#endif
173}
174
175
177{
179
180 m_settings.m_warpCursor = cfg->m_Input.center_on_zoom;
181 m_settings.m_focusFollowSchPcb = cfg->m_Input.focus_follow_sch_pcb;
182 m_settings.m_autoPanSettingEnabled = cfg->m_Input.auto_pan;
183 m_settings.m_autoPanAcceleration = cfg->m_Input.auto_pan_acceleration;
184 m_settings.m_horizontalPan = cfg->m_Input.horizontal_pan;
185 m_settings.m_zoomAcceleration = cfg->m_Input.zoom_acceleration;
186 m_settings.m_zoomSpeed = cfg->m_Input.zoom_speed;
187 m_settings.m_zoomSpeedAuto = cfg->m_Input.zoom_speed_auto;
188 m_settings.m_scrollModifierZoom = cfg->m_Input.scroll_modifier_zoom;
189 m_settings.m_scrollModifierPanH = cfg->m_Input.scroll_modifier_pan_h;
190 m_settings.m_scrollModifierPanV = cfg->m_Input.scroll_modifier_pan_v;
191 m_settings.m_dragLeft = cfg->m_Input.drag_left;
192 m_settings.m_dragMiddle = cfg->m_Input.drag_middle;
193 m_settings.m_dragRight = cfg->m_Input.drag_right;
194 m_settings.m_scrollReverseZoom = cfg->m_Input.reverse_scroll_zoom;
195 m_settings.m_scrollReversePanH = cfg->m_Input.reverse_scroll_pan_h;
196 m_settings.m_motionPanModifier = cfg->m_Input.motion_pan_modifier;
197
198 m_zoomController.reset();
199
200 if( cfg->m_Input.zoom_speed_auto )
201 {
203 }
204 else
205 {
206 if( cfg->m_Input.zoom_acceleration )
207 {
209 std::make_unique<ACCELERATING_ZOOM_CONTROLLER>( cfg->m_Input.zoom_speed );
210 }
211 else
212 {
214
215 m_zoomController = std::make_unique<CONSTANT_ZOOM_CONTROLLER>( scale );
216 }
217 }
218}
219
220
221void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
222{
224
225#ifdef KICAD_GAL_PROFILE
226 latencyProbeRepaintToMotion.Checkpoint("motion-event");
227 wxLogTrace( traceGalProfile, "%s", latencyProbeRepaintToMotion.to_string() );
228 latencyProbeZoomToRender.Reset();
229#endif
230
231 ( *m_MotionEventCounter )++;
232
233 // Because Weston sends a motion event to previous location after warping the pointer
234 wxPoint mouseRel = m_parentPanel->ScreenToClient( KIPLATFORM::UI::GetMousePosition() );
235
236 // Enter and leave events can be dropped, so trust motion inside the canvas. onLeave() reuses
237 // this handler with its own leave event
238 if( !aEvent.Leaving() && m_parentPanel->GetClientRect().Contains( mouseRel ) )
239 m_parentPanel->SetCursorInCanvas( true );
240
241 bool isAutoPanning = false;
242 int x = mouseRel.x;
243 int y = mouseRel.y;
244 VECTOR2D mousePos( x, y );
245
246 // Clear keyboard cursor position flag when actual mouse motion is detected
247 // (i.e., not from cursor warping and position has changed)
248 if( !m_cursorWarped && m_settings.m_lastKeyboardCursorPositionValid )
249 {
250 VECTOR2I screenPos( x, y );
251 VECTOR2I keyboardScreenPos = m_view->ToScreen( m_settings.m_lastKeyboardCursorPosition );
252
253 // If mouse has moved to a different position than the keyboard cursor position,
254 // clear the keyboard position flag to allow mouse control
255 if( screenPos != keyboardScreenPos )
256 {
257 m_settings.m_lastKeyboardCursorPositionValid = false;
258 m_settings.m_lastKeyboardCursorPosition = { 0.0, 0.0 };
259 }
260 }
261
262 // Automatic focus switching between SCH and PCB windows on canvas mouse motion
263 if( m_settings.m_focusFollowSchPcb )
264 {
265 if( EDA_DRAW_FRAME* frame = m_parentPanel->GetParentEDAFrame() )
266 {
267 KIWAY_PLAYER* otherFrame = nullptr;
268
269 if( frame->IsType( FRAME_PCB_EDITOR ) )
270 {
271 otherFrame = frame->Kiway().Player( FRAME_SCH, false );
272 }
273 else if( frame->IsType( FRAME_SCH ) )
274 {
275 otherFrame = frame->Kiway().Player( FRAME_PCB_EDITOR, false );
276 }
277
278 if( otherFrame && KIPLATFORM::UI::IsWindowActive( otherFrame )
279 && !KIPLATFORM::UI::IsWindowActive( frame ) )
280 {
281 frame->Raise();
282 }
283 }
284 }
285
286 if( m_settings.m_motionPanModifier != WXK_NONE
287 && wxGetKeyState( static_cast<wxKeyCode>( m_settings.m_motionPanModifier ) ) )
288 {
289 if( !m_metaPanning )
290 {
291 m_metaPanning = true;
292 m_metaPanStart = mousePos;
293 aEvent.StopPropagation();
294 }
295 else
296 {
297 VECTOR2D d = m_metaPanStart - mousePos;
298 m_metaPanStart = mousePos;
299 VECTOR2D delta = m_view->ToWorld( d, false );
300 m_view->SetCenter( m_view->GetCenter() + delta );
301 aEvent.StopPropagation();
302 }
303
304 if( m_updateCursor )
305 m_cursorPos = GetClampedCoords( m_view->ToWorld( mousePos ) );
306 else
307 m_updateCursor = true;
308
310 aEvent.Skip();
311 return;
312 }
313 else
314 {
315 m_metaPanning = false;
316 }
317
319 handleCursorCapture( x, y );
320
321 if( m_settings.m_autoPanEnabled && m_settings.m_autoPanSettingEnabled )
322 isAutoPanning = handleAutoPanning( aEvent );
323
324 if( !isAutoPanning && aEvent.Dragging() )
325 {
326 if( m_state == DRAG_PANNING )
327 {
328 static bool justWarped = false;
329 int warpX = 0;
330 int warpY = 0;
331 wxSize parentSize = m_parentPanel->GetClientSize();
332
333 if( x < 0 )
334 {
335 warpX = parentSize.x;
336 }
337 else if( x >= parentSize.x )
338 {
339 warpX = -parentSize.x;
340 }
341
342 if( y < 0 )
343 {
344 warpY = parentSize.y;
345 }
346 else if( y >= parentSize.y )
347 {
348 warpY = -parentSize.y;
349 }
350
351 if( !justWarped )
352 {
353 VECTOR2D d = m_dragStartPoint - mousePos;
354 m_dragStartPoint = mousePos;
355 VECTOR2D delta = m_view->ToWorld( d, false );
356#ifdef KICAD_GAL_PROFILE
357 latencyProbeZoomToRender.Checkpoint("mouse-mb-pan");
358#endif
359 m_view->SetCenter( m_view->GetCenter() + delta );
360 aEvent.StopPropagation();
361 }
362
363 if( warpX || warpY )
364 {
365 if( !justWarped )
366 {
367 if( m_infinitePanWorks && KIPLATFORM::UI::WarpPointer( m_parentPanel, x + warpX, y + warpY ) )
368 {
369 m_dragStartPoint += VECTOR2D( warpX, warpY );
370 justWarped = true;
371 }
372 }
373 else
374 {
375 justWarped = false;
376 }
377 }
378 else
379 {
380 justWarped = false;
381 }
382 }
383 else if( m_state == DRAG_ZOOMING )
384 {
385 static bool justWarped = false;
386 int warpY = 0;
387 wxSize parentSize = m_parentPanel->GetClientSize();
388
389 if( y < 0 )
390 {
391 warpY = parentSize.y;
392 }
393 else if( y >= parentSize.y )
394 {
395 warpY = -parentSize.y;
396 }
397
398 if( !justWarped )
399 {
400 VECTOR2D d = m_dragStartPoint - mousePos;
401 m_dragStartPoint = mousePos;
402
403 double scale = exp( d.y * m_settings.m_zoomSpeed * 0.001 );
404
405 wxLogTrace( traceZoomScroll, wxString::Format( "dy: %f scale: %f", d.y, scale ) );
406
407 m_view->SetScale( m_view->GetScale() * scale, m_view->ToWorld( m_zoomStartPoint ) );
408 aEvent.StopPropagation();
409 }
410
411 if( warpY )
412 {
413 if( !justWarped )
414 {
416 m_dragStartPoint += VECTOR2D( 0, warpY );
417 justWarped = true;
418 }
419 else
420 justWarped = false;
421 }
422 else
423 {
424 justWarped = false;
425 }
426 }
427 }
428
429 if( m_updateCursor ) // do not update the cursor position if it was explicitly set
430 m_cursorPos = GetClampedCoords( m_view->ToWorld( mousePos ) );
431 else
432 m_updateCursor = true;
433
434 // EDA_DRAW_PANEL_GAL::OnEvent repaints after the tools see the motion. Painting here would draw
435 // the cursor ahead of what the tools draw for it.
436 aEvent.Skip();
437}
438
439
441{
442 if( m_view->GetGAL() && m_view->GetGAL()->HasRetainedScene() )
443 m_parentPanel->Refresh();
444}
445
446
447void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
448{
450
451 const double wheelPanSpeed = 0.001;
452 const int axis = aEvent.GetWheelAxis();
453
454#ifdef KICAD_GAL_PROFILE
455 latencyProbeZoomToRender.Reset();
456#endif
457
458 // Native horizontal wheel events (tilt wheels, side-button scroll combos, touchpads) pan the
459 // view when "Pan left/right with horizontal movement" is enabled, otherwise they are ignored
460 if( axis == wxMOUSE_WHEEL_HORIZONTAL )
461 {
462 if( !m_settings.m_horizontalPan )
463 return;
464
465 VECTOR2D scrollVec = m_view->ToWorld( m_view->GetGAL()->GetLayoutPixelSize(), false )
466 * ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
467
468 m_view->SetCenter( m_view->GetCenter() + VECTOR2D( scrollVec.x, 0.0 ) );
469 refreshMouse( true );
471 return;
472 }
473
474 // Pick the modifier, if any. Shift beats control beats alt, we don't support more than one.
475 int nMods = 0;
476 int modifiers = 0;
477
478 if( aEvent.ShiftDown() )
479 {
480 nMods += 1;
481 modifiers = WXK_SHIFT;
482 }
483
484 if( aEvent.ControlDown() )
485 {
486 nMods += 1;
487 modifiers = modifiers == 0 ? WXK_CONTROL : modifiers;
488 }
489
490 if( aEvent.AltDown() )
491 {
492 nMods += 1;
493 modifiers = modifiers == 0 ? WXK_ALT : modifiers;
494 }
495
496 // Zero or one modifier is view control
497 if( nMods <= 1 )
498 {
499 // Restrict zoom handling to the vertical axis, otherwise horizontal
500 // scrolling events (e.g. touchpads and some mice) end up interpreted
501 // as vertical scroll events and confuse the user.
502 if( modifiers == m_settings.m_scrollModifierZoom && axis == wxMOUSE_WHEEL_VERTICAL )
503 {
504 const int rotation = aEvent.GetWheelRotation() * ( m_settings.m_scrollReverseZoom ? -1 : 1 );
505
506 // macOS reports a scroll distance rather than notches, so its rotation is never compounded
507#ifdef __WXMAC__
508 const int wheelDelta = 0;
509#else
510 const int wheelDelta = aEvent.GetWheelDelta();
511#endif
512
513 const double zoomScale = m_zoomController->GetScaleForRotation( rotation, wheelDelta );
514
515
516#ifdef KICAD_GAL_PROFILE
517 wxLogTrace( traceGalProfile, "Zoom: %.5f", m_view->GetScale() * zoomScale );
518 latencyProbeZoomToRender.Checkpoint("mouse-wheel-zoom");
519#endif
520
522 {
524 m_view->SetScale( m_view->GetScale() * zoomScale );
525 }
526 else
527 {
528 const VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
529 m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
530 }
531
532 // Refresh the zoom level and mouse position on message panel
533 // (mouse position has not changed, only the zoom level has changed):
534 refreshMouse( true );
536 }
537 else
538 {
539 // Scrolling
540 VECTOR2D scrollVec = m_view->ToWorld( m_view->GetGAL()->GetLayoutPixelSize(), false )
541 * ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
542 double scrollX = 0.0;
543 double scrollY = 0.0;
544 bool hReverse = m_settings.m_scrollReversePanH;
545
546 if( modifiers == m_settings.m_scrollModifierPanH )
547 {
548 scrollX = hReverse ? scrollVec.x : -scrollVec.x;
549 }
550 else
551 {
552 scrollY = -scrollVec.y;
553 }
554
555 VECTOR2D delta( scrollX, scrollY );
556
557 m_view->SetCenter( m_view->GetCenter() + delta );
558 refreshMouse( true );
560 }
561
562 // Do not skip this event, otherwise wxWidgets will fire
563 // 3 wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN (normal wxWidgets behavior)
564 // and we do not want that.
565 }
566 else
567 {
568 // When we have multiple mods, forward it for tool handling
569 aEvent.Skip();
570 }
571}
572
573
574void WX_VIEW_CONTROLS::onMagnify( wxMouseEvent& aEvent )
575{
576 // Scale based on the magnification from our underlying magnification event.
577 VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
578 m_view->SetScale( m_view->GetScale() * ( aEvent.GetMagnification() + 1.0f ), anchor );
579
581 aEvent.Skip();
582}
583
584
586{
587 m_state = aNewState;
588}
589
590
591void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
592{
593 switch( m_state )
594 {
595 case IDLE:
596 case AUTO_PANNING:
597 if( ( aEvent.MiddleDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::PAN )
598 || ( aEvent.RightDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::PAN ) )
599 {
600 m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
603
604#if defined USE_MOUSE_CAPTURE
605 if( !m_parentPanel->HasCapture() )
606 m_parentPanel->CaptureMouse();
607#endif
608 }
609 else if( ( aEvent.MiddleDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::ZOOM )
610 || ( aEvent.RightDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::ZOOM ) )
611 {
612 m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
615
616#if defined USE_MOUSE_CAPTURE
617 if( !m_parentPanel->HasCapture() )
618 m_parentPanel->CaptureMouse();
619#endif
620 }
621
622 if( aEvent.LeftUp() )
623 setState( IDLE ); // Stop autopanning when user release left mouse button
624
625 break;
626
627 case DRAG_ZOOMING:
628 case DRAG_PANNING:
629 if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
630 {
631 setState( IDLE );
633
634#if defined USE_MOUSE_CAPTURE
635 if( !m_settings.m_cursorCaptured && m_parentPanel->HasCapture() )
636 m_parentPanel->ReleaseMouse();
637
639#endif
640 }
641
642 break;
643 }
644
645 aEvent.Skip();
646}
647
648
649void WX_VIEW_CONTROLS::onEnter( wxMouseEvent& aEvent )
650{
651 m_parentPanel->SetCursorInCanvas( true );
652
653 // Avoid stealing focus from text controls
654 // This is particularly important for users using On-Screen-Keyboards
655 // They may move the mouse over the canvas to reach the keyboard
657 {
658 return;
659 }
660
661#if defined( _WIN32 ) || defined( __WXGTK__ )
662 // Win32 and some *nix WMs transmit mouse move and wheel events to all controls below the
663 // mouse regardless of focus. Forcing the focus here will cause the EDA FRAMES to immediately
664 // become the top level active window.
665 if( m_parentPanel->GetParent() != nullptr )
666 {
667 // this assumes the parent panel's parent is the eda window
669 {
670 m_parentPanel->SetFocus();
671 }
672 }
673#else
674 m_parentPanel->SetFocus();
675#endif
676}
677
678
679void WX_VIEW_CONTROLS::onLeave( wxMouseEvent& aEvent )
680{
681 // MSW sends a leave event when the capture starts, but no enter event follows.
682 if( m_parentPanel->HasCapture() )
683 return;
684
685 // A leave inside the client area while the pointer is still ours is a crossing into the GAL child
686 bool crossingIntoChild = m_parentPanel->GetClientRect().Contains( aEvent.GetPosition() ) && isPointerOverCanvas();
687
688 if( !crossingIntoChild )
689 m_parentPanel->SetCursorInCanvas( false );
690
691#if !defined USE_MOUSE_CAPTURE
692 onMotion( aEvent );
693#endif
694}
695
696
697void WX_VIEW_CONTROLS::onCaptureLost( wxMouseEvent& aEvent )
698{
699 // This method must be present to suppress the capture-lost assertion
700
701 // Set the flag to allow calling m_parentPanel->CaptureMouse()
702 // Note: One cannot call m_parentPanel->CaptureMouse() twice, this is not accepted
703 // by wxWidgets (MSW specific) so we need this guard
704 m_parentPanel->m_MouseCapturedLost = true;
705
707}
708
709
711{
712 // Leave events are ignored while captured, so the capture holder keeps the cursor
713 m_parentPanel->SetCursorInCanvas( m_parentPanel->HasCapture() || isPointerOverCanvas() );
714}
715
716
718{
719 wxWindow* under = wxFindWindowAtPoint( KIPLATFORM::UI::GetMousePosition() );
720
721 return under && ( under == m_parentPanel || m_parentPanel->IsDescendant( under ) );
722}
723
724
725void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
726{
727 switch( m_state )
728 {
729 case AUTO_PANNING:
730 {
731 if( !m_settings.m_autoPanEnabled )
732 {
733 setState( IDLE );
734 return;
735 }
736
737#ifdef __WXMSW__
738 // Hackfix: It's possible for the mouse to leave the canvas
739 // without triggering any leave events on windows
740 // Use a MSW only wx function
741 if( !m_parentPanel->IsMouseInWindow() )
742 {
743 m_panTimer.Stop();
744 setState( IDLE );
745 return;
746 }
747#endif
748
749 if( !m_parentPanel->HasFocus() && !m_parentPanel->StatusPopupHasFocus() )
750 {
751 setState( IDLE );
752 return;
753 }
754
755 double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
756 m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().y );
757
758 // When the mouse cursor is outside the area with no pan,
759 // m_panDirection is the dist to this area limit ( in pixels )
760 // It will be used also as pan value (the pan speed depends on this dist).
762
763 // When the mouse cursor is outside the area with no pan, the pan value
764 // is accelerated depending on the dist between the area and the cursor
765 float accel = 0.5f + ( m_settings.m_autoPanAcceleration / 5.0f );
766
767 // For a small mouse cursor dist to area, just use the distance.
768 // But for a dist > borderSize / 2, use an accelerated pan value
769
770 if( dir.EuclideanNorm() >= borderSize ) // far from area limits
771 dir = dir.Resize( borderSize * accel );
772 else if( dir.EuclideanNorm() > borderSize / 2 ) // Near from area limits
773 dir = dir.Resize( borderSize );
774
775 dir = m_view->ToWorld( dir, false );
776 m_view->SetCenter( m_view->GetCenter() + dir );
777
778 refreshMouse( true );
780
781 m_panTimer.Start();
782 }
783 break;
784
785 case IDLE: // Just remove unnecessary warnings
786 case DRAG_PANNING:
787 case DRAG_ZOOMING: break;
788 }
789}
790
791
792void WX_VIEW_CONTROLS::onZoomGesture( wxZoomGestureEvent& aEvent )
793{
794 if( aEvent.IsGestureStart() )
795 {
797 m_gestureLastPos = VECTOR2D( aEvent.GetPosition().x, aEvent.GetPosition().y );
798 }
799
800 VECTOR2D evtPos( aEvent.GetPosition().x, aEvent.GetPosition().y );
802 aEvent.GetZoomFactor() / m_gestureLastZoomFactor, evtPos );
803
804 m_gestureLastZoomFactor = aEvent.GetZoomFactor();
805 m_gestureLastPos = evtPos;
806}
807
808
809void WX_VIEW_CONTROLS::onPanGesture( wxPanGestureEvent& aEvent )
810{
811 // GTK reports a left button drag as a pan when the panel itself takes the mouse. That drag
812 // belongs to the tools.
813 if( wxGetMouseState().LeftIsDown() )
814 {
815 aEvent.Skip();
816 return;
817 }
818
819 VECTOR2I screenDelta( aEvent.GetDelta().x, aEvent.GetDelta().y );
820
821 ApplyPanAndZoomGesture( screenDelta, 1.0, VECTOR2D() );
822}
823
824
825void WX_VIEW_CONTROLS::ApplyPanAndZoomGesture( const VECTOR2D& aPanDelta, double aZoomFactor,
826 const VECTOR2D& aZoomAnchor )
827{
828 VECTOR2D deltaWorld = m_view->ToWorld( aPanDelta, false );
829
830 m_view->SetCenter( m_view->GetCenter() - deltaWorld );
831
832 if( std::isfinite( aZoomFactor ) && aZoomFactor > 0.0 && aZoomFactor != 1.0 )
833 m_view->SetScale( m_view->GetScale() * aZoomFactor, m_view->ToWorld( aZoomAnchor ) );
834
835 refreshMouse( true );
836}
837
838
839void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent )
840{
841 const double linePanDelta = 0.05;
842 const double pagePanDelta = 0.5;
843
844 int type = aEvent.GetEventType();
845 int dir = aEvent.GetOrientation();
846
847 if( type == wxEVT_SCROLLWIN_THUMBTRACK )
848 {
849 auto center = m_view->GetCenter();
850 const auto& boundary = m_view->GetBoundary();
851
852 // Flip scroll direction in flipped view
853 const double xstart = ( m_view->IsMirroredX() ? boundary.GetRight() : boundary.GetLeft() );
854 const double xdelta = ( m_view->IsMirroredX() ? -1 : 1 );
855
856 if( dir == wxHORIZONTAL )
857 center.x = xstart + xdelta * ( aEvent.GetPosition() / m_scrollScale.x );
858 else
859 center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
860
861 m_view->SetCenter( center );
862 }
863 else if( type == wxEVT_SCROLLWIN_THUMBRELEASE || type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLLWIN_BOTTOM )
864 {
865 // Do nothing on thumb release, we don't care about it.
866 // We don't have a concept of top or bottom in our viewport, so ignore those events.
867 }
868 else
869 {
870 double dist = 0;
871
872 if( type == wxEVT_SCROLLWIN_PAGEUP )
873 {
874 dist = pagePanDelta;
875 }
876 else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
877 {
878 dist = -pagePanDelta;
879 }
880 else if( type == wxEVT_SCROLLWIN_LINEUP )
881 {
882 dist = linePanDelta;
883 }
884 else if( type == wxEVT_SCROLLWIN_LINEDOWN )
885 {
886 dist = -linePanDelta;
887 }
888 else
889 {
890 wxCHECK_MSG( false, /* void */, wxT( "Unhandled event type" ) );
891 }
892
893 VECTOR2D scroll = m_view->ToWorld( m_view->GetGAL()->GetLayoutPixelSize(), false ) * dist;
894
895 double scrollX = 0.0;
896 double scrollY = 0.0;
897
898 if( dir == wxHORIZONTAL )
899 scrollX = -scroll.x;
900 else
901 scrollY = -scroll.y;
902
903 VECTOR2D delta( scrollX, scrollY );
904
905 m_view->SetCenter( m_view->GetCenter() + delta );
906 }
907
908 m_parentPanel->Refresh();
909}
910
911
913{
914#if defined USE_MOUSE_CAPTURE
915 // Note: for some reason, m_parentPanel->HasCapture() can be false even if CaptureMouse()
916 // was called (i.e. mouse was captured, so when need to test m_MouseCapturedLost to be
917 // sure a wxEVT_MOUSE_CAPTURE_LOST event was fired before. Otherwise wxMSW complains
918 // The IsModalDialogFocused is checked because it's possible to start a capture
919 // due to event ordering while a modal dialog was just opened, the mouse capture steels focus
920 // from the modal and causes odd behavior
921 if( aEnabled && !m_parentPanel->HasCapture() && m_parentPanel->m_MouseCapturedLost
923 {
924 m_parentPanel->CaptureMouse();
925
926 // Clear the flag to allow calling m_parentPanel->CaptureMouse()
927 // Calling it without calling ReleaseMouse() is not accepted by wxWidgets (MSW specific)
928 m_parentPanel->m_MouseCapturedLost = false;
929 }
930 else if( !aEnabled && m_parentPanel->HasCapture() && m_state != DRAG_PANNING && m_state != DRAG_ZOOMING )
931 {
932 m_parentPanel->ReleaseMouse();
933
934 // Mouse is released, calling CaptureMouse() is allowed now:
935 m_parentPanel->m_MouseCapturedLost = true;
936
938 }
939#endif
941}
942
943
945{
947 {
948 setState( IDLE );
949
950#if defined USE_MOUSE_CAPTURE
951 if( !m_settings.m_cursorCaptured && m_parentPanel->HasCapture() )
952 m_parentPanel->ReleaseMouse();
953
955#endif
956 }
957
958 m_metaPanning = false;
959}
960
961
962VECTOR2D WX_VIEW_CONTROLS::GetMousePosition( bool aWorldCoordinates ) const
963{
964 wxPoint msp = getMouseScreenPosition();
965 VECTOR2D screenPos( msp.x, msp.y );
966
967 return aWorldCoordinates ? GetClampedCoords( m_view->ToWorld( screenPos ) ) : screenPos;
968}
969
970
972{
973 GAL* gal = m_view->GetGAL();
974
975 if( aEnableSnapping && gal->GetGridSnapping() )
976 {
977 return gal->GetGridPoint( m_cursorPos );
978 }
979 else
980 {
981 return m_cursorPos;
982 }
983}
984
985
987{
988 if( m_settings.m_forceCursorPosition )
989 {
990 return m_settings.m_forcedPosition;
991 }
992 else
993 {
994 return GetClampedCoords( GetRawCursorPosition( aEnableSnapping ) );
995 }
996}
997
998
999void WX_VIEW_CONTROLS::SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView, bool aTriggeredByArrows,
1000 long aArrowCommand )
1001{
1002 m_updateCursor = false;
1003
1004 VECTOR2D clampedPosition = GetClampedCoords( aPosition );
1005
1006 if( aTriggeredByArrows )
1007 {
1008 m_settings.m_lastKeyboardCursorPositionValid = true;
1009 m_settings.m_lastKeyboardCursorPosition = clampedPosition;
1010 m_settings.m_lastKeyboardCursorCommand = aArrowCommand;
1011 m_cursorWarped = false;
1012 }
1013 else
1014 {
1015 m_settings.m_lastKeyboardCursorPositionValid = false;
1016 m_settings.m_lastKeyboardCursorPosition = { 0.0, 0.0 };
1017 m_settings.m_lastKeyboardCursorCommand = 0;
1018 m_cursorWarped = true;
1019 }
1020
1021 WarpMouseCursor( clampedPosition, true, aWarpView );
1022 m_cursorPos = clampedPosition;
1023}
1024
1025
1026void WX_VIEW_CONTROLS::SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true )
1027{
1028 m_updateCursor = false;
1029
1030 VECTOR2D clampedPosition = GetClampedCoords( aPosition );
1031
1032 const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
1033 BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
1034 VECTOR2D screenPos = m_view->ToScreen( clampedPosition );
1035
1036 if( aWarpView && !screen.Contains( screenPos ) )
1037 m_view->SetCenter( clampedPosition );
1038
1039 m_cursorPos = clampedPosition;
1040}
1041
1042
1043void WX_VIEW_CONTROLS::WarpMouseCursor( const VECTOR2D& aPosition, bool aWorldCoordinates, bool aWarpView )
1044{
1045 if( aWorldCoordinates )
1046 {
1047 const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
1048 BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
1049 VECTOR2D clampedPosition = GetClampedCoords( aPosition );
1050 VECTOR2D screenPos = m_view->ToScreen( clampedPosition );
1051
1052 if( !screen.Contains( screenPos ) )
1053 {
1054 if( aWarpView )
1055 {
1056 m_view->SetCenter( clampedPosition );
1057 KIPLATFORM::UI::WarpPointer( m_parentPanel, screenSize.x / 2, screenSize.y / 2 );
1058 }
1059 }
1060 else
1061 {
1062 KIPLATFORM::UI::WarpPointer( m_parentPanel, screenPos.x, screenPos.y );
1063 }
1064 }
1065 else
1066 {
1067 KIPLATFORM::UI::WarpPointer( m_parentPanel, aPosition.x, aPosition.y );
1068 }
1069
1070 // If we are not refreshing because of mouse movement, don't set the modifiers because we
1071 // are refreshing for keyboard movement, which uses the same modifiers for other actions
1073}
1074
1075
1077{
1078 const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
1079 VECTOR2D screenCenter( screenSize / 2 );
1080
1081 if( GetMousePosition( false ) != screenCenter )
1082 {
1083 VECTOR2D newCenter = GetCursorPosition();
1084
1085 if( KIPLATFORM::UI::WarpPointer( m_parentPanel, screenCenter.x, screenCenter.y ) )
1086 {
1087 m_view->SetCenter( newCenter );
1088 m_dragStartPoint = screenCenter;
1089 }
1090 }
1091}
1092
1093
1095{
1096 int border = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
1097 m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().y );
1098 border += 2;
1099
1100 VECTOR2D topLeft( border, border );
1101 VECTOR2D botRight( m_view->GetScreenPixelSize().x - border, m_view->GetScreenPixelSize().y - border );
1102
1103 topLeft = m_view->ToWorld( topLeft );
1104 botRight = m_view->ToWorld( botRight );
1105
1106 VECTOR2D pos = GetMousePosition( true );
1107
1108 if( pos.x < topLeft.x )
1109 pos.x = topLeft.x;
1110 else if( pos.x > botRight.x )
1111 pos.x = botRight.x;
1112
1113 if( pos.y < topLeft.y )
1114 pos.y = topLeft.y;
1115 else if( pos.y > botRight.y )
1116 pos.y = botRight.y;
1117
1118 SetCursorPosition( pos, false, false, 0 );
1119
1120 if( aWarpMouseCursor )
1121 WarpMouseCursor( pos, true );
1122}
1123
1124
1125bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
1126{
1127 VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
1128 VECTOR2I pKey( m_view->ToScreen( m_settings.m_lastKeyboardCursorPosition ) );
1129
1130 if( m_cursorWarped || ( m_settings.m_lastKeyboardCursorPositionValid && p == pKey ) )
1131 {
1132 // last cursor move event came from keyboard cursor control. If auto-panning is enabled
1133 // and the next position is inside the autopan zone, check if it really came from a mouse
1134 // event, otherwise disable autopan temporarily. Also temporarily disable autopan if the
1135 // cursor is in the autopan zone because the application warped the cursor.
1136
1137 m_cursorWarped = false;
1138 return true;
1139 }
1140
1141 m_cursorWarped = false;
1142
1143 // Compute areas where autopanning is active
1144 int borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
1145 m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().y );
1146 borderStart = std::max( borderStart, 2 );
1147 int borderEndX = m_view->GetScreenPixelSize().x - borderStart;
1148 int borderEndY = m_view->GetScreenPixelSize().y - borderStart;
1149
1150 if( p.x < borderStart )
1151 m_panDirection.x = -( borderStart - p.x );
1152 else if( p.x > borderEndX )
1153 m_panDirection.x = ( p.x - borderEndX );
1154 else
1155 m_panDirection.x = 0;
1156
1157 if( p.y < borderStart )
1158 m_panDirection.y = -( borderStart - p.y );
1159 else if( p.y > borderEndY )
1160 m_panDirection.y = ( p.y - borderEndY );
1161 else
1162 m_panDirection.y = 0;
1163
1164 bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
1165
1166 switch( m_state )
1167 {
1168 case AUTO_PANNING:
1169 if( !borderHit )
1170 {
1171 m_panTimer.Stop();
1172 setState( IDLE );
1173
1174 return false;
1175 }
1176
1177 return true;
1178
1179 case IDLE:
1180 if( borderHit )
1181 {
1183 m_panTimer.Start( (int) ( 250.0 / 60.0 ), true );
1184
1185 return true;
1186 }
1187
1188 return false;
1189
1190 case DRAG_PANNING:
1191 case DRAG_ZOOMING: return false;
1192 }
1193
1194 wxCHECK_MSG( false, false, wxT( "This line should never be reached" ) );
1195
1196 return false;
1197}
1198
1199
1201{
1202 if( m_settings.m_cursorCaptured )
1203 {
1204 bool warp = false;
1205 wxSize parentSize = m_parentPanel->GetClientSize();
1206
1207 if( x < 0 )
1208 {
1209 x = 0;
1210 warp = true;
1211 }
1212 else if( x >= parentSize.x )
1213 {
1214 x = parentSize.x - 1;
1215 warp = true;
1216 }
1217
1218 if( y < 0 )
1219 {
1220 y = 0;
1221 warp = true;
1222 }
1223 else if( y >= parentSize.y )
1224 {
1225 y = parentSize.y - 1;
1226 warp = true;
1227 }
1228
1229 if( warp )
1231 }
1232}
1233
1234
1235void WX_VIEW_CONTROLS::refreshMouse( bool aSetModifiers )
1236{
1237 // Notify tools that the cursor position has changed in the world coordinates
1238 wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
1239 wxPoint msp = getMouseScreenPosition();
1240 moveEvent.SetX( msp.x );
1241 moveEvent.SetY( msp.y );
1242
1243 if( aSetModifiers )
1244 {
1245 // Set the modifiers state
1246 moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
1247 moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
1248 moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
1249 }
1250
1251 m_cursorPos = GetClampedCoords( m_view->ToWorld( VECTOR2D( msp.x, msp.y ) ) );
1252 wxPostEvent( m_parentPanel, moveEvent );
1253}
1254
1255
1257{
1258 wxPoint msp = KIPLATFORM::UI::GetMousePosition();
1259 m_parentPanel->ScreenToClient( &msp.x, &msp.y );
1260 return msp;
1261}
1262
1263
1265{
1266 const BOX2D viewport = m_view->GetViewport();
1267 const BOX2D& boundary = m_view->GetBoundary();
1268
1269 m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
1270 m_scrollScale.y = 2e3 / viewport.GetHeight();
1271 VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
1272 ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
1273
1274 // We add the width of the scroll bar thumb to the range because the scroll range is given by
1275 // the full bar while the position is given by the left/top position of the thumb
1276 VECTOR2I newRange( m_scrollScale.x * boundary.GetWidth() + m_parentPanel->GetScrollThumb( wxSB_HORIZONTAL ),
1277 m_scrollScale.y * boundary.GetHeight() + m_parentPanel->GetScrollThumb( wxSB_VERTICAL ) );
1278
1279 // Flip scroll direction in flipped view
1280 if( m_view->IsMirroredX() )
1281 newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x;
1282
1283 // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuously
1284 // refreshed (Windows)
1285 if( m_scrollPos != newScroll || newRange.x != m_parentPanel->GetScrollRange( wxSB_HORIZONTAL )
1286 || newRange.y != m_parentPanel->GetScrollRange( wxSB_VERTICAL ) )
1287 {
1288 m_parentPanel->SetScrollbars( 1, 1, newRange.x, newRange.y, newScroll.x, newScroll.y, true );
1289 m_scrollPos = newScroll;
1290
1291#if !defined( __APPLE__ ) && !defined( WIN32 )
1292 // Trigger a mouse refresh to get the canvas update in GTK (re-draws the scrollbars).
1293 // Note that this causes an infinite loop on OSX and Windows (in certain cases) as it
1294 // generates a paint event.
1295 refreshMouse( false );
1296#endif
1297 }
1298}
1299
1300
1301void WX_VIEW_CONTROLS::ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition )
1302{
1303 VECTOR2D clampedPosition = GetClampedCoords( aPosition );
1304
1305 m_settings.m_forceCursorPosition = aEnabled;
1306 m_settings.m_forcedPosition = clampedPosition;
1307}
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
BOX2< VECTOR2D > BOX2D
Definition box2.h:918
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr Vec Centre() const
Definition box2.h:100
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr coord_type GetTop() const
Definition box2.h:232
The base class for create windows for drawing purpose.
static void NoteInput()
Count an input so the frame that answers it is never held back by the display-rate limit.
static constexpr double MAC_SCALE
A suitable (magic) scale factor for Mac systems.
static constexpr double MSW_SCALE
A suitable (magic) scale factor for Windows systems.
static constexpr double GTK3_SCALE
A suitable (magic) scale factor for GTK3 systems.
static constexpr double MANUAL_SCALE_FACTOR
Multiplier for manual scale ssetting.
Abstract interface for drawing on a 2D-surface.
VECTOR2D GetGridPoint(const VECTOR2D &aPoint) const
For a given point it returns the nearest point belonging to the grid in world coordinates.
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
bool m_cursorWarped
Application warped the cursor, not the user (keyboard).
bool IsCursorWarpingEnabled() const
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings.
VIEW * m_view
Pointer to controlled VIEW.
VIEW_CONTROLS(VIEW *aView)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
bool m_infinitePanWorks
Flag to indicate if infinite panning works on this platform.
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
void ApplyPanAndZoomGesture(const VECTOR2D &aPanDelta, double aZoomFactor, const VECTOR2D &aZoomAnchor)
Apply a platform gesture expressed in canvas pixel coordinates.
void LoadSettings() override
Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS.
void setState(STATE aNewState)
Set the interaction state, simply a internal setter to make it easier to debug changes.
STATE m_state
Current state of VIEW_CONTROLS.
void CaptureCursor(bool aEnabled) override
Force the cursor to stay within the drawing panel area.
VECTOR2D m_metaPanStart
Last mouse position when panning via the meta key.
bool m_metaPanning
True if we are panning via the meta key.
void onScroll(wxScrollWinEvent &aEvent)
wxTimer m_panTimer
Timer responsible for handling autopanning.
void CancelDrag()
End any mouse drag action still in progress.
void repaintRetained()
Repaint only when the canvas keeps a retained scene.
void onButton(wxMouseEvent &aEvent)
double m_gestureLastZoomFactor
Used to track gesture events.
void onEnter(wxMouseEvent &WXUNUSED(aEvent))
void onWheel(wxMouseEvent &aEvent)
Handler functions.
VECTOR2I m_scrollPos
Current scrollbar position.
void refreshMouse(bool aSetModifiers)
Send an event to refresh mouse position.
WX_VIEW_CONTROLS(VIEW *aView, EDA_DRAW_PANEL_GAL *aParentPanel)
void onZoomGesture(wxZoomGestureEvent &aEvent)
void PinCursorInsideNonAutoscrollArea(bool aWarpMouseCursor) override
void SetCursorPosition(const VECTOR2D &aPosition, bool warpView, bool aTriggeredByArrows, long aArrowCommand) override
Move cursor to the requested position expressed in world coordinates.
VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const override
Return the current mouse pointer position.
void WarpMouseCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) override
If enabled (.
void onMagnify(wxMouseEvent &aEvent)
VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const override
Return the current cursor position in world coordinates ignoring the cursorUp position force mode.
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
bool handleAutoPanning(const wxMouseEvent &aEvent)
Compute new viewport settings while in autopanning mode.
wxPoint getMouseScreenPosition() const
Get the cursor position in the screen coordinates.
void syncCursorInCanvas()
Set the panel's cursor-in-canvas state from the pointer position after a capture change.
void onPanGesture(wxPanGestureEvent &aEvent)
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
A ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
STATE
Possible states for WX_VIEW_CONTROLS.
@ DRAG_PANNING
Panning with mouse button pressed.
@ AUTO_PANNING
Panning on approaching borders of the frame.
@ DRAG_ZOOMING
Zooming with mouse button pressed.
@ IDLE
Nothing is happening.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
void CenterOnCursor() override
Set the viewport center to the current cursor position and warps the cursor to the screen center.
VECTOR2D m_cursorPos
Current cursor position (world coordinates).
void onCaptureLost(wxMouseEvent &WXUNUSED(aEvent))
void onMotion(wxMouseEvent &aEvent)
std::unique_ptr< PROF_COUNTER > m_MotionEventCounter
EDA_DRAW_PANEL_GAL * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void UpdateScrollbars()
Adjusts the scrollbars position to match the current viewport.
void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0)) override
Place the cursor immediately at a given point.
void handleCursorCapture(int x, int y)
Limit the cursor position to within the canvas by warping it.
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_zoomStartPoint
The mouse position when a drag zoom started.
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
VECTOR2D m_panDirection
Current direction of panning (only autopanning mode).
VECTOR2D m_dragStartPoint
Store information about point where dragging has started.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition kiway.cpp:407
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:600
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:281
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:406
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ FRAME_SCH
Definition frame_type.h:30
a few functions useful in geometry calculations.
VECTOR2< ret_type > GetClampedCoords(const VECTOR2< in_type > &aCoords, pad_type aPadding=1u)
Clamp a vector to values that can be negated, respecting numeric limits of coordinates data type with...
const wxChar *const traceZoomScroll
Flag to enable debug output of zoom-scrolling calculations in KIGFX::ZOOM_CONTROLLER and derivatives.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
void InfiniteDragReleaseWindow()
On Wayland, allows the cursor to freely move again after a drag (see InfiniteDragPrepareWindow).
bool WarpPointer(wxWindow *aWindow, int aX, int aY)
Move the mouse cursor to a specific position relative to the window.
Definition wxgtk/ui.cpp:638
bool IsWindowActive(wxWindow *aWindow)
Check to see if the given window is the currently active window (e.g.
Definition wxgtk/ui.cpp:233
bool InfiniteDragPrepareWindow(wxWindow *aWindow)
On Wayland, restricts the pointer movement to a rectangle slightly bigger than the given wxWindow.
KICOMMON_API bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
KICOMMON_API bool IsModalDialogFocused()
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
const int scale
MOUSE_DRAG_ACTION drag_right
MOUSE_DRAG_ACTION drag_middle
MOUSE_DRAG_ACTION drag_left
VECTOR2I center
int delta
wxLogTrace helper definitions.
Functions to provide common constants and other functions to assist in making a consistent UI.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
static std::unique_ptr< ZOOM_CONTROLLER > GetZoomControllerForPlatform(bool aAcceleration)
WX_VIEW_CONTROLS class definition.
ZOOM_CONTROLLER class definition.