source: git/src/guicontrol.cc @ e0f3ade

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since e0f3ade was e0f3ade, checked in by Olly Betts <olly@…>, 10 years ago

src/guicontrol.cc: If dragging with more than one mouse button held
down, releasing one causes another which is still held down to take
effect.

  • Property mode set to 100644
File size: 29.1 KB
Line 
1//
2//  guicontrol.cc
3//
4//  Handlers for events relating to the display of a survey.
5//
6//  Copyright (C) 2000-2002,2005 Mark R. Shinwell
7//  Copyright (C) 2001,2003,2004,2005,2006,2011,2012,2014 Olly Betts
8//
9//  This program is free software; you can redistribute it and/or modify
10//  it under the terms of the GNU General Public License as published by
11//  the Free Software Foundation; either version 2 of the License, or
12//  (at your option) any later version.
13//
14//  This program is distributed in the hope that it will be useful,
15//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17//  GNU General Public License for more details.
18//
19//  You should have received a copy of the GNU General Public License
20//  along with this program; if not, write to the Free Software
21//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22//
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include "guicontrol.h"
29#include "gfxcore.h"
30#include <wx/confbase.h>
31
32const int DISPLAY_SHIFT = 10;
33const double FLYFREE_SHIFT = 0.2;
34const double ROTATE_STEP = 2.0;
35
36GUIControl::GUIControl()
37    : dragging(NO_DRAG)
38{
39    m_View = NULL;
40    m_ReverseControls = false;
41    m_LastDrag = drag_NONE;
42}
43
44void GUIControl::SetView(GfxCore* view)
45{
46    m_View = view;
47}
48
49bool GUIControl::MouseDown() const
50{
51    return (dragging != NO_DRAG);
52}
53
54void GUIControl::HandleTilt(wxPoint point)
55{
56    // Handle a mouse movement during tilt mode.
57
58    // wxGTK (at least) fails to update the cursor while dragging.
59    m_View->SetCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
60
61    int dy = point.y - m_DragStart.y;
62
63    if (m_ReverseControls != m_View->GetPerspective()) dy = -dy;
64
65    m_View->TiltCave(Double(dy) * 0.36);
66
67    m_DragStart = point;
68
69    m_View->ForceRefresh();
70}
71
72void GUIControl::HandleTranslate(wxPoint point)
73{
74    // Handle a mouse movement during translation mode.
75
76    // wxGTK (at least) fails to update the cursor while dragging.
77    m_View->SetCursor(GfxCore::CURSOR_DRAGGING_HAND);
78
79    int dx = point.x - m_DragStart.x;
80    int dy = point.y - m_DragStart.y;
81
82    if (m_ReverseControls) {
83        dx = -dx;
84        dy = -dy;
85    }
86
87    if (m_View->GetPerspective())
88        m_View->MoveViewer(0, -dy * .1, dx * .1);
89    else
90        m_View->TranslateCave(dx, dy);
91
92    m_DragStart = point;
93}
94
95void GUIControl::HandleScaleRotate(wxPoint point)
96{
97    // Handle a mouse movement during scale/rotate mode.
98
99    // wxGTK (at least) fails to update the cursor while dragging.
100    m_View->SetCursor(GfxCore::CURSOR_ZOOM_ROTATE);
101
102    int dx, dy;
103    int threshold;
104    if (m_ScaleRotateLock == lock_NONE) {
105        // Dragging to scale or rotate but we've not decided which yet.
106        dx = point.x - m_DragRealStart.x;
107        dy = point.y - m_DragRealStart.y;
108        threshold = 8 * 8;
109    } else {
110        dx = point.x - m_DragStart.x;
111        dy = point.y - m_DragStart.y;
112        threshold = 5;
113    }
114    int dx2 = dx * dx;
115    int dy2 = dy * dy;
116    if (dx2 + dy2 < threshold) return;
117
118    switch (m_ScaleRotateLock) {
119        case lock_NONE:
120            if (dx2 > dy2) {
121                m_ScaleRotateLock = lock_ROTATE;
122//              m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
123            } else {
124                m_ScaleRotateLock = lock_SCALE;
125//              m_View->SetCursor(GfxCore::CURSOR_ZOOM);
126            }
127            break;
128        case lock_SCALE:
129            if (dx2 >= 8 * dy2) {
130                m_ScaleRotateLock = lock_ROTATE;
131//              m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
132            }
133            break;
134        case lock_ROTATE:
135            if (dy2 >= 8 * dx2) {
136                m_ScaleRotateLock = lock_SCALE;
137//              m_View->SetCursor(GfxCore::CURSOR_ZOOM);
138            }
139            break;
140    }
141
142    if (m_ScaleRotateLock == lock_ROTATE) {
143        dy = 0;
144    } else {
145        dx = 0;
146    }
147
148    if (m_ReverseControls) {
149        dx = -dx;
150        dy = -dy;
151    }
152
153    if (m_View->GetPerspective()) {
154        if (dy) m_View->MoveViewer(-dy * .1, 0, 0);
155    } else {
156        // up/down => scale.
157        if (dy) m_View->SetScale(m_View->GetScale() * pow(1.06, 0.08 * dy));
158        // left/right => rotate.
159        if (dx) m_View->TurnCave(Double(dx) * -0.36);
160        if (dx || dy) m_View->ForceRefresh();
161    }
162
163    m_DragStart = point;
164}
165
166void GUIControl::HandleTiltRotate(wxPoint point)
167{
168    // Handle a mouse movement during tilt/rotate mode.
169    if (m_View->IsExtendedElevation()) return;
170
171    // wxGTK (at least) fails to update the cursor while dragging.
172    m_View->SetCursor(GfxCore::CURSOR_ROTATE_EITHER_WAY);
173
174    int dx = point.x - m_DragStart.x;
175    int dy = point.y - m_DragStart.y;
176
177    if (m_ReverseControls != m_View->GetPerspective()) {
178        dx = -dx;
179        dy = -dy;
180    }
181
182    // left/right => rotate, up/down => tilt.
183    // Make tilt less sensitive than rotate as that feels better.
184    m_View->TurnCave(Double(dx) * -0.36);
185    m_View->TiltCave(Double(dy) * 0.18);
186
187    m_View->ForceRefresh();
188
189    m_DragStart = point;
190}
191
192void GUIControl::HandleRotate(wxPoint point)
193{
194    // Handle a mouse movement during rotate mode.
195    if (m_View->IsExtendedElevation()) return;
196
197    // wxGTK (at least) fails to update the cursor while dragging.
198    m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
199
200    int dx = point.x - m_DragStart.x;
201    int dy = point.y - m_DragStart.y;
202
203    if (m_ReverseControls != m_View->GetPerspective()) {
204        dx = -dx;
205        dy = -dy;
206    }
207
208    // left/right => rotate.
209    m_View->TurnCave(Double(dx) * -0.36);
210
211    m_View->ForceRefresh();
212
213    m_DragStart = point;
214}
215
216void GUIControl::RestoreCursor()
217{
218    if (m_View->HereIsReal()) {
219        m_View->SetCursor(GfxCore::CURSOR_POINTING_HAND);
220    } else {
221        m_View->SetCursor(GfxCore::CURSOR_DEFAULT);
222    }
223}
224
225void GUIControl::HandleNonDrag(const wxPoint & point) {
226    if (m_View->CheckHitTestGrid(point, false)) {
227        m_View->SetCursor(GfxCore::CURSOR_POINTING_HAND);
228    } else if (m_View->PointWithinScaleBar(point)) {
229        m_View->SetCursor(GfxCore::CURSOR_HORIZONTAL_RESIZE);
230    } else if (m_View->PointWithinCompass(point)) {
231        m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
232    } else if (m_View->PointWithinClino(point)) {
233        m_View->SetCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
234    } else {
235        RestoreCursor();
236    }
237}
238
239//
240//  Mouse event handling methods
241//
242
243void GUIControl::OnMouseMove(wxMouseEvent& event)
244{
245    // Mouse motion event handler.
246    if (!m_View->HasData()) return;
247
248    // Ignore moves which don't change the position.
249    if (event.GetPosition() == m_DragStart) {
250        return;
251    }
252
253    static long timestamp = LONG_MIN;
254    if (dragging != NO_DRAG && m_ScaleRotateLock != lock_NONE &&
255        timestamp != LONG_MIN) {
256        // If no motion for a second, reset the direction lock.
257        if (event.GetTimestamp() - timestamp >= 1000) {
258            m_ScaleRotateLock = lock_NONE;
259            m_DragRealStart = m_DragStart;
260            RestoreCursor();
261        }
262    }
263    timestamp = event.GetTimestamp();
264
265    wxPoint point(event.GetPosition());
266
267    // Check hit-test grid (only if no buttons are pressed).
268    if (!event.LeftIsDown() && !event.MiddleIsDown() && !event.RightIsDown()) {
269        HandleNonDrag(point);
270    }
271
272    // Update coordinate display if in plan view,
273    // or altitude if in elevation view.
274    m_View->SetCoords(point);
275
276    switch (dragging) {
277        case LEFT_DRAG:
278            switch (m_LastDrag) {
279                case drag_COMPASS:
280                    // Drag in heading indicator.
281                    m_View->SetCompassFromPoint(point);
282                    break;
283                case drag_ELEV:
284                    // Drag in clinometer.
285                    m_View->SetClinoFromPoint(point);
286                    break;
287                case drag_SCALE:
288                    m_View->SetScaleBarFromOffset(point.x - m_DragLast.x);
289                    break;
290                case drag_MAIN:
291                    if (event.ControlDown()) {
292                        HandleTiltRotate(point);
293                    } else {
294                        HandleScaleRotate(point);
295                    }
296                    break;
297                case drag_NONE:
298                    // Shouldn't happen?!  FIXME: assert or something.
299                    break;
300            }
301            break;
302        case MIDDLE_DRAG:
303            HandleTilt(point);
304            break;
305        case RIGHT_DRAG:
306            HandleTranslate(point);
307            break;
308        case NO_DRAG:
309            break;
310    }
311
312    m_DragLast = point;
313}
314
315void GUIControl::OnLButtonDown(wxMouseEvent& event)
316{
317    if (m_View->HasData()) {
318        m_DragStart = m_DragRealStart = event.GetPosition();
319
320        if (m_View->PointWithinCompass(m_DragStart)) {
321            m_LastDrag = drag_COMPASS;
322            m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
323        } else if (m_View->PointWithinClino(m_DragStart)) {
324            m_LastDrag = drag_ELEV;
325            m_View->SetCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
326        } else if (m_View->PointWithinScaleBar(m_DragStart)) {
327            m_LastDrag = drag_SCALE;
328            m_View->SetCursor(GfxCore::CURSOR_HORIZONTAL_RESIZE);
329        } else {
330            if (event.ControlDown() && !m_View->IsExtendedElevation()) {
331                m_View->SetCursor(GfxCore::CURSOR_ROTATE_EITHER_WAY);
332            } else {
333                m_View->SetCursor(GfxCore::CURSOR_ZOOM_ROTATE);
334            }
335
336            m_LastDrag = drag_MAIN;
337            m_ScaleRotateLock = lock_NONE;
338        }
339
340        // We need to release and recapture for the cursor to update (noticed
341        // with wxGTK).
342        if (dragging != NO_DRAG) m_View->ReleaseMouse();
343        m_View->CaptureMouse();
344
345        dragging = LEFT_DRAG;
346    }
347}
348
349void GUIControl::OnLButtonUp(wxMouseEvent& event)
350{
351    if (m_View->HasData()) {
352        if (dragging != LEFT_DRAG)
353            return;
354
355        if (event.GetPosition() == m_DragRealStart) {
356            // Just a "click"...
357            m_View->CheckHitTestGrid(m_DragStart, true);
358        }
359
360        if (event.MiddleIsDown()) {
361            OnMButtonDown(event);
362            return;
363        }
364
365        if (event.RightIsDown()) {
366            OnRButtonDown(event);
367            return;
368        }
369
370        m_View->ReleaseMouse();
371
372        m_LastDrag = drag_NONE;
373        dragging = NO_DRAG;
374
375        m_View->DragFinished();
376
377        if (event.GetPosition() == m_DragRealStart) {
378            RestoreCursor();
379        } else {
380            HandleNonDrag(event.GetPosition());
381        }
382    }
383}
384
385void GUIControl::OnMButtonDown(wxMouseEvent& event)
386{
387    if (m_View->HasData() && !m_View->IsExtendedElevation()) {
388        m_DragStart = event.GetPosition();
389
390        m_View->SetCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
391
392        // We need to release and recapture for the cursor to update (noticed
393        // with wxGTK).
394        if (dragging != NO_DRAG) m_View->ReleaseMouse();
395        m_View->CaptureMouse();
396        dragging = MIDDLE_DRAG;
397    }
398}
399
400void GUIControl::OnMButtonUp(wxMouseEvent& event)
401{
402    if (m_View->HasData()) {
403        if (dragging != MIDDLE_DRAG)
404            return;
405
406        if (event.LeftIsDown()) {
407            OnLButtonDown(event);
408            return;
409        }
410
411        if (event.RightIsDown()) {
412            OnRButtonDown(event);
413            return;
414        }
415
416        dragging = NO_DRAG;
417        m_View->ReleaseMouse();
418        m_View->DragFinished();
419
420        RestoreCursor();
421    }
422}
423
424void GUIControl::OnRButtonDown(wxMouseEvent& event)
425{
426    if (m_View->HasData()) {
427        if (m_View->HandleRClick(event.GetPosition()))
428            return;
429
430        m_DragStart = event.GetPosition();
431
432        m_View->SetCursor(GfxCore::CURSOR_DRAGGING_HAND);
433
434        // We need to release and recapture for the cursor to update (noticed
435        // with wxGTK).
436        if (dragging != NO_DRAG) m_View->ReleaseMouse();
437        m_View->CaptureMouse();
438        dragging = RIGHT_DRAG;
439    }
440}
441
442void GUIControl::OnRButtonUp(wxMouseEvent& event)
443{
444    if (dragging != RIGHT_DRAG)
445        return;
446
447    if (event.LeftIsDown()) {
448        OnLButtonDown(event);
449        return;
450    }
451
452    if (event.MiddleIsDown()) {
453        OnMButtonDown(event);
454        return;
455    }
456
457    m_LastDrag = drag_NONE;
458    m_View->ReleaseMouse();
459
460    dragging = NO_DRAG;
461
462    RestoreCursor();
463
464    m_View->DragFinished();
465}
466
467void GUIControl::OnMouseWheel(wxMouseEvent& event) {
468    int dy = event.GetWheelRotation();
469    if (m_View->GetPerspective()) {
470        m_View->MoveViewer(-dy, 0, 0);
471    } else {
472        m_View->SetScale(m_View->GetScale() * pow(1.06, -0.04 * dy));
473        m_View->ForceRefresh();
474    }
475}
476
477void GUIControl::OnDisplayOverlappingNames()
478{
479    m_View->ToggleOverlappingNames();
480}
481
482void GUIControl::OnDisplayOverlappingNamesUpdate(wxUpdateUIEvent& cmd)
483{
484    cmd.Enable(m_View->HasData() && m_View->ShowingStationNames());
485    cmd.Check(m_View->ShowingOverlappingNames());
486}
487
488void GUIControl::OnColourByDepth()
489{
490    if (m_View->ColouringBy() == COLOUR_BY_DEPTH) {
491        m_View->SetColourBy(COLOUR_BY_NONE);
492    } else {
493        m_View->SetColourBy(COLOUR_BY_DEPTH);
494    }
495}
496
497void GUIControl::OnColourByDate()
498{
499    if (m_View->ColouringBy() == COLOUR_BY_DATE) {
500        m_View->SetColourBy(COLOUR_BY_NONE);
501    } else {
502        m_View->SetColourBy(COLOUR_BY_DATE);
503    }
504}
505
506void GUIControl::OnColourByError()
507{
508    if (m_View->ColouringBy() == COLOUR_BY_ERROR) {
509        m_View->SetColourBy(COLOUR_BY_NONE);
510    } else {
511        m_View->SetColourBy(COLOUR_BY_ERROR);
512    }
513}
514
515void GUIControl::OnColourByDepthUpdate(wxUpdateUIEvent& cmd)
516{
517    cmd.Enable(m_View->HasData());
518    cmd.Check(m_View->ColouringBy() == COLOUR_BY_DEPTH);
519}
520
521void GUIControl::OnColourByDateUpdate(wxUpdateUIEvent& cmd)
522{
523    cmd.Enable(m_View->HasData());
524    cmd.Check(m_View->ColouringBy() == COLOUR_BY_DATE);
525}
526
527void GUIControl::OnColourByErrorUpdate(wxUpdateUIEvent& cmd)
528{
529    cmd.Enable(m_View->HasData());
530    cmd.Check(m_View->ColouringBy() == COLOUR_BY_ERROR);
531}
532
533void GUIControl::OnShowCrosses()
534{
535    m_View->ToggleCrosses();
536}
537
538void GUIControl::OnShowCrossesUpdate(wxUpdateUIEvent& cmd)
539{
540    cmd.Enable(m_View->HasData());
541    cmd.Check(m_View->ShowingCrosses());
542}
543
544void GUIControl::OnShowStationNames()
545{
546    m_View->ToggleStationNames();
547}
548
549void GUIControl::OnShowStationNamesUpdate(wxUpdateUIEvent& cmd)
550{
551    cmd.Enable(m_View->HasData());
552    cmd.Check(m_View->ShowingStationNames());
553}
554
555void GUIControl::OnShowSurveyLegs()
556{
557    m_View->ToggleUndergroundLegs();
558}
559
560void GUIControl::OnShowSurveyLegsUpdate(wxUpdateUIEvent& cmd)
561{
562    cmd.Enable(m_View->HasData() && m_View->HasUndergroundLegs());
563    cmd.Check(m_View->ShowingUndergroundLegs());
564}
565
566void GUIControl::OnHideSplays()
567{
568    m_View->SetSplaysMode(SPLAYS_HIDE);
569}
570
571void GUIControl::OnShowSplaysNormal()
572{
573    m_View->SetSplaysMode(SPLAYS_SHOW_NORMAL);
574}
575
576void GUIControl::OnShowSplaysFaded()
577{
578    m_View->SetSplaysMode(SPLAYS_SHOW_FADED);
579}
580
581void GUIControl::OnSplaysUpdate(wxUpdateUIEvent& cmd)
582{
583    cmd.Enable(m_View->HasData() && m_View->HasSplays());
584}
585
586void GUIControl::OnHideSplaysUpdate(wxUpdateUIEvent& cmd)
587{
588    cmd.Enable(m_View->HasData() && m_View->HasSplays());
589    cmd.Check(m_View->ShowingSplaysMode() == SPLAYS_HIDE);
590}
591
592void GUIControl::OnShowSplaysNormalUpdate(wxUpdateUIEvent& cmd)
593{
594    cmd.Enable(m_View->HasData() && m_View->HasSplays());
595    cmd.Check(m_View->ShowingSplaysMode() == SPLAYS_SHOW_NORMAL);
596}
597
598void GUIControl::OnShowSplaysFadedUpdate(wxUpdateUIEvent& cmd)
599{
600    cmd.Enable(m_View->HasData() && m_View->HasSplays());
601    cmd.Check(m_View->ShowingSplaysMode() == SPLAYS_SHOW_FADED);
602}
603
604void GUIControl::OnMoveEast()
605{
606    m_View->TurnCaveTo(90.0);
607    m_View->ForceRefresh();
608}
609
610void GUIControl::OnMoveEastUpdate(wxUpdateUIEvent& cmd)
611{
612    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && m_View->GetCompassValue() != 90.0);
613}
614
615void GUIControl::OnMoveNorth()
616{
617    m_View->TurnCaveTo(0.0);
618    m_View->ForceRefresh();
619}
620
621void GUIControl::OnMoveNorthUpdate(wxUpdateUIEvent& cmd)
622{
623    cmd.Enable(m_View->HasData() && m_View->GetCompassValue() != 0.0);
624}
625
626void GUIControl::OnMoveSouth()
627{
628    m_View->TurnCaveTo(180.0);
629    m_View->ForceRefresh();
630}
631
632void GUIControl::OnMoveSouthUpdate(wxUpdateUIEvent& cmd)
633{
634    cmd.Enable(m_View->HasData() && m_View->GetCompassValue() != 180.0);
635}
636
637void GUIControl::OnMoveWest()
638{
639    m_View->TurnCaveTo(270.0);
640    m_View->ForceRefresh();
641}
642
643void GUIControl::OnMoveWestUpdate(wxUpdateUIEvent& cmd)
644{
645    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && m_View->GetCompassValue() != 270.0);
646}
647
648void GUIControl::OnToggleRotation()
649{
650    m_View->ToggleRotation();
651}
652
653void GUIControl::OnToggleRotationUpdate(wxUpdateUIEvent& cmd)
654{
655    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
656    cmd.Check(m_View->HasData() && m_View->IsRotating());
657}
658
659void GUIControl::OnReverseControls()
660{
661    m_ReverseControls = !m_ReverseControls;
662}
663
664void GUIControl::OnReverseControlsUpdate(wxUpdateUIEvent& cmd)
665{
666    cmd.Enable(m_View->HasData());
667    cmd.Check(m_ReverseControls);
668}
669
670void GUIControl::OnReverseDirectionOfRotation()
671{
672    m_View->ReverseRotation();
673}
674
675void GUIControl::OnReverseDirectionOfRotationUpdate(wxUpdateUIEvent& cmd)
676{
677    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
678}
679
680void GUIControl::OnSlowDown(bool accel)
681{
682    m_View->RotateSlower(accel);
683}
684
685void GUIControl::OnSlowDownUpdate(wxUpdateUIEvent& cmd)
686{
687    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
688}
689
690void GUIControl::OnSpeedUp(bool accel)
691{
692    m_View->RotateFaster(accel);
693}
694
695void GUIControl::OnSpeedUpUpdate(wxUpdateUIEvent& cmd)
696{
697    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
698}
699
700void GUIControl::OnStepOnceAnticlockwise(bool accel)
701{
702    if (m_View->GetPerspective()) {
703        m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
704    } else {
705        m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
706    }
707    m_View->ForceRefresh();
708}
709
710void GUIControl::OnStepOnceAnticlockwiseUpdate(wxUpdateUIEvent& cmd)
711{
712    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->IsRotating());
713}
714
715void GUIControl::OnStepOnceClockwise(bool accel)
716{
717    if (m_View->GetPerspective()) {
718        m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
719    } else {
720        m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
721    }
722    m_View->ForceRefresh();
723}
724
725void GUIControl::OnStepOnceClockwiseUpdate(wxUpdateUIEvent& cmd)
726{
727    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->IsRotating());
728}
729
730void GUIControl::OnDefaults()
731{
732    m_View->Defaults();
733}
734
735void GUIControl::OnDefaultsUpdate(wxUpdateUIEvent& cmd)
736{
737    cmd.Enable(m_View->HasData());
738}
739
740void GUIControl::OnElevation()
741{
742    // Switch to elevation view.
743
744    m_View->SwitchToElevation();
745}
746
747void GUIControl::OnElevationUpdate(wxUpdateUIEvent& cmd)
748{
749    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->ShowingElevation());
750}
751
752void GUIControl::OnHigherViewpoint(bool accel)
753{
754    // Raise the viewpoint.
755    if (m_View->GetPerspective()) {
756        m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
757    } else {
758        m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
759    }
760    m_View->ForceRefresh();
761}
762
763void GUIControl::OnHigherViewpointUpdate(wxUpdateUIEvent& cmd)
764{
765    cmd.Enable(m_View->HasData() && m_View->CanRaiseViewpoint() && !m_View->IsExtendedElevation());
766}
767
768void GUIControl::OnLowerViewpoint(bool accel)
769{
770    // Lower the viewpoint.
771    if (m_View->GetPerspective()) {
772        m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
773    } else {
774        m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
775    }
776    m_View->ForceRefresh();
777}
778
779void GUIControl::OnLowerViewpointUpdate(wxUpdateUIEvent& cmd)
780{
781    cmd.Enable(m_View->HasData() && m_View->CanLowerViewpoint() && !m_View->IsExtendedElevation());
782}
783
784void GUIControl::OnPlan()
785{
786    // Switch to plan view.
787    m_View->SwitchToPlan();
788}
789
790void GUIControl::OnPlanUpdate(wxUpdateUIEvent& cmd)
791{
792    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->ShowingPlan());
793}
794
795void GUIControl::OnShiftDisplayDown(bool accel)
796{
797    if (m_View->GetPerspective())
798        m_View->MoveViewer(0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0);
799    else
800        m_View->TranslateCave(0, accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT);
801}
802
803void GUIControl::OnShiftDisplayDownUpdate(wxUpdateUIEvent& cmd)
804{
805    cmd.Enable(m_View->HasData());
806}
807
808void GUIControl::OnShiftDisplayLeft(bool accel)
809{
810    if (m_View->GetPerspective())
811        m_View->MoveViewer(0, 0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT);
812    else
813        m_View->TranslateCave(accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT, 0);
814}
815
816void GUIControl::OnShiftDisplayLeftUpdate(wxUpdateUIEvent& cmd)
817{
818    cmd.Enable(m_View->HasData());
819}
820
821void GUIControl::OnShiftDisplayRight(bool accel)
822{
823    if (m_View->GetPerspective())
824        m_View->MoveViewer(0, 0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT);
825    else
826        m_View->TranslateCave(accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT, 0);
827}
828
829void GUIControl::OnShiftDisplayRightUpdate(wxUpdateUIEvent& cmd)
830{
831    cmd.Enable(m_View->HasData());
832}
833
834void GUIControl::OnShiftDisplayUp(bool accel)
835{
836    if (m_View->GetPerspective())
837        m_View->MoveViewer(0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0);
838    else
839        m_View->TranslateCave(0, accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT);
840}
841
842void GUIControl::OnShiftDisplayUpUpdate(wxUpdateUIEvent& cmd)
843{
844    cmd.Enable(m_View->HasData());
845}
846
847void GUIControl::OnZoomIn(bool accel)
848{
849    // Increase the scale.
850
851    if (m_View->GetPerspective()) {
852        m_View->MoveViewer(accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0, 0);
853    } else {
854        m_View->SetScale(m_View->GetScale() * (accel ? 1.1236 : 1.06));
855        m_View->ForceRefresh();
856    }
857}
858
859void GUIControl::OnZoomInUpdate(wxUpdateUIEvent& cmd)
860{
861    cmd.Enable(m_View->HasData());
862}
863
864void GUIControl::OnZoomOut(bool accel)
865{
866    // Decrease the scale.
867
868    if (m_View->GetPerspective()) {
869        m_View->MoveViewer(accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0, 0);
870    } else {
871        m_View->SetScale(m_View->GetScale() / (accel ? 1.1236 : 1.06));
872        m_View->ForceRefresh();
873    }
874}
875
876void GUIControl::OnZoomOutUpdate(wxUpdateUIEvent& cmd)
877{
878    cmd.Enable(m_View->HasData());
879}
880
881void GUIControl::OnToggleScalebar()
882{
883    m_View->ToggleScaleBar();
884}
885
886void GUIControl::OnToggleScalebarUpdate(wxUpdateUIEvent& cmd)
887{
888    cmd.Enable(m_View->HasData());
889    cmd.Check(m_View->ShowingScaleBar());
890}
891
892void GUIControl::OnToggleColourKey()
893{
894    m_View->ToggleColourKey();
895}
896
897void GUIControl::OnToggleColourKeyUpdate(wxUpdateUIEvent& cmd)
898{
899    cmd.Enable(m_View->HasData() && m_View->ColouringBy() != COLOUR_BY_NONE);
900    cmd.Check(m_View->ShowingColourKey());
901}
902
903void GUIControl::OnViewCompass()
904{
905    m_View->ToggleCompass();
906}
907
908void GUIControl::OnViewCompassUpdate(wxUpdateUIEvent& cmd)
909{
910    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
911    cmd.Check(m_View->ShowingCompass());
912}
913
914void GUIControl::OnViewClino()
915{
916    m_View->ToggleClino();
917}
918
919void GUIControl::OnViewClinoUpdate(wxUpdateUIEvent& cmd)
920{
921    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
922    cmd.Check(m_View->ShowingClino());
923}
924
925void GUIControl::OnShowSurface()
926{
927    m_View->ToggleSurfaceLegs();
928}
929
930void GUIControl::OnShowSurfaceUpdate(wxUpdateUIEvent& cmd)
931{
932    cmd.Enable(m_View->HasData() && m_View->HasSurfaceLegs());
933    cmd.Check(m_View->ShowingSurfaceLegs());
934}
935
936void GUIControl::OnShowEntrances()
937{
938    m_View->ToggleEntrances();
939}
940
941void GUIControl::OnShowEntrancesUpdate(wxUpdateUIEvent& cmd)
942{
943    cmd.Enable(m_View->HasData() && (m_View->GetNumEntrances() > 0));
944    cmd.Check(m_View->ShowingEntrances());
945}
946
947void GUIControl::OnShowFixedPts()
948{
949    m_View->ToggleFixedPts();
950}
951
952void GUIControl::OnShowFixedPtsUpdate(wxUpdateUIEvent& cmd)
953{
954    cmd.Enable(m_View->HasData() && (m_View->GetNumFixedPts() > 0));
955    cmd.Check(m_View->ShowingFixedPts());
956}
957
958void GUIControl::OnShowExportedPts()
959{
960    m_View->ToggleExportedPts();
961}
962
963void GUIControl::OnShowExportedPtsUpdate(wxUpdateUIEvent& cmd)
964{
965    cmd.Enable(m_View->HasData() && (m_View->GetNumExportedPts() > 0));
966    cmd.Check(m_View->ShowingExportedPts());
967}
968
969void GUIControl::OnViewGrid()
970{
971    m_View->ToggleGrid();
972}
973
974void GUIControl::OnViewGridUpdate(wxUpdateUIEvent& cmd)
975{
976    cmd.Enable(m_View->HasData());
977    cmd.Check(m_View->ShowingGrid());
978}
979
980void GUIControl::OnIndicatorsUpdate(wxUpdateUIEvent& cmd)
981{
982    cmd.Enable(m_View->HasData());
983}
984
985void GUIControl::OnViewPerspective()
986{
987    m_View->TogglePerspective();
988    // Force update of coordinate display.
989    if (m_View->GetPerspective()) {
990        m_View->MoveViewer(0, 0, 0);
991    } else {
992        m_View->ClearCoords();
993    }
994}
995
996void GUIControl::OnViewPerspectiveUpdate(wxUpdateUIEvent& cmd)
997{
998    cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
999    cmd.Check(m_View->GetPerspective());
1000}
1001
1002void GUIControl::OnViewSmoothShading()
1003{
1004    m_View->ToggleSmoothShading();
1005}
1006
1007void GUIControl::OnViewSmoothShadingUpdate(wxUpdateUIEvent& cmd)
1008{
1009    cmd.Enable(m_View->HasData());
1010    cmd.Check(m_View->GetSmoothShading());
1011}
1012
1013void GUIControl::OnViewTextured()
1014{
1015    m_View->ToggleTextured();
1016}
1017
1018void GUIControl::OnViewTexturedUpdate(wxUpdateUIEvent& cmd)
1019{
1020    cmd.Enable(m_View->HasData());
1021    cmd.Check(m_View->GetTextured());
1022}
1023
1024void GUIControl::OnViewFog()
1025{
1026    m_View->ToggleFog();
1027}
1028
1029void GUIControl::OnViewFogUpdate(wxUpdateUIEvent& cmd)
1030{
1031    cmd.Enable(m_View->HasData());
1032    cmd.Check(m_View->GetFog());
1033}
1034
1035void GUIControl::OnViewSmoothLines()
1036{
1037    m_View->ToggleAntiAlias();
1038}
1039
1040void GUIControl::OnViewSmoothLinesUpdate(wxUpdateUIEvent& cmd)
1041{
1042    cmd.Enable(m_View->HasData());
1043    cmd.Check(m_View->GetAntiAlias());
1044}
1045
1046void GUIControl::OnToggleMetric()
1047{
1048    m_View->ToggleMetric();
1049
1050    wxConfigBase::Get()->Write(wxT("metric"), m_View->GetMetric());
1051    wxConfigBase::Get()->Flush();
1052}
1053
1054void GUIControl::OnToggleMetricUpdate(wxUpdateUIEvent& cmd)
1055{
1056    cmd.Enable(m_View->HasData());
1057    cmd.Check(m_View->GetMetric());
1058}
1059
1060void GUIControl::OnToggleDegrees()
1061{
1062    m_View->ToggleDegrees();
1063
1064    wxConfigBase::Get()->Write(wxT("degrees"), m_View->GetDegrees());
1065    wxConfigBase::Get()->Flush();
1066}
1067
1068void GUIControl::OnToggleDegreesUpdate(wxUpdateUIEvent& cmd)
1069{
1070    cmd.Enable(m_View->HasData());
1071    cmd.Check(m_View->GetDegrees());
1072}
1073
1074void GUIControl::OnToggleTubes()
1075{
1076    m_View->ToggleTubes();
1077}
1078
1079void GUIControl::OnToggleTubesUpdate(wxUpdateUIEvent& cmd)
1080{
1081    cmd.Enable(m_View->HasData() && m_View->HasTubes());
1082    cmd.Check(m_View->GetTubes());
1083}
1084
1085void GUIControl::OnCancelDistLine()
1086{
1087    m_View->ClearTreeSelection();
1088}
1089
1090void GUIControl::OnCancelDistLineUpdate(wxUpdateUIEvent& cmd)
1091{
1092    cmd.Enable(m_View->ShowingMeasuringLine());
1093}
1094
1095void GUIControl::OnKeyPress(wxKeyEvent &e)
1096{
1097    if (!m_View->HasData()) {
1098        e.Skip();
1099        return;
1100    }
1101
1102    // The changelog says this is meant to keep animation going while keys are
1103    // pressed, but that happens anyway (on linux at least - perhaps it helps
1104    // on windows?)  FIXME : check!
1105    //bool refresh = m_View->Animate();
1106
1107    switch (e.GetKeyCode()) {
1108        case '/': case '?':
1109            if (m_View->CanLowerViewpoint() && !m_View->IsExtendedElevation())
1110                OnLowerViewpoint(e.GetModifiers() == wxMOD_SHIFT);
1111            break;
1112        case '\'': case '@': case '"': // both shifted forms - US and UK kbd
1113            if (m_View->CanRaiseViewpoint() && !m_View->IsExtendedElevation())
1114                OnHigherViewpoint(e.GetModifiers() == wxMOD_SHIFT);
1115            break;
1116        case 'C': case 'c':
1117            if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1118                OnStepOnceAnticlockwise(e.GetModifiers() == wxMOD_SHIFT);
1119            break;
1120        case 'V': case 'v':
1121            if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1122                OnStepOnceClockwise(e.GetModifiers() == wxMOD_SHIFT);
1123            break;
1124        case ']': case '}':
1125            OnZoomIn(e.GetModifiers() == wxMOD_SHIFT);
1126            break;
1127        case '[': case '{':
1128            OnZoomOut(e.GetModifiers() == wxMOD_SHIFT);
1129            break;
1130        case 'N': case 'n':
1131            OnMoveNorth();
1132            break;
1133        case 'S': case 's':
1134            OnMoveSouth();
1135            break;
1136        case 'E': case 'e':
1137            if (!m_View->IsExtendedElevation())
1138                OnMoveEast();
1139            break;
1140        case 'W': case 'w':
1141            if (!m_View->IsExtendedElevation())
1142                OnMoveWest();
1143            break;
1144        case 'Z': case 'z':
1145            if (!m_View->IsExtendedElevation())
1146                OnSpeedUp(e.GetModifiers() == wxMOD_SHIFT);
1147            break;
1148        case 'X': case 'x':
1149            if (!m_View->IsExtendedElevation())
1150                OnSlowDown(e.GetModifiers() == wxMOD_SHIFT);
1151            break;
1152        case 'R': case 'r':
1153            if (!m_View->IsExtendedElevation())
1154                OnReverseDirectionOfRotation();
1155            break;
1156        case 'P': case 'p':
1157            if (!m_View->IsExtendedElevation() && !m_View->ShowingPlan())
1158                OnPlan();
1159            break;
1160        case 'L': case 'l':
1161            if (!m_View->IsExtendedElevation() && !m_View->ShowingElevation())
1162                OnElevation();
1163            break;
1164        case 'O': case 'o':
1165            OnDisplayOverlappingNames();
1166            break;
1167        case WXK_DELETE:
1168            OnDefaults();
1169            break;
1170        case WXK_RETURN:
1171            // For compatibility with older versions.
1172            if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1173                m_View->StartRotation();
1174            break;
1175        case WXK_SPACE:
1176            if (!m_View->IsExtendedElevation())
1177                OnToggleRotation();
1178            break;
1179        case WXK_LEFT:
1180            if ((e.GetModifiers() &~ wxMOD_SHIFT) == wxMOD_CONTROL) {
1181                if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1182                    OnStepOnceAnticlockwise(e.GetModifiers() == wxMOD_SHIFT);
1183            } else {
1184                OnShiftDisplayLeft(e.GetModifiers() == wxMOD_SHIFT);
1185            }
1186            break;
1187        case WXK_RIGHT:
1188            if ((e.GetModifiers() &~ wxMOD_SHIFT) == wxMOD_CONTROL) {
1189                if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1190                    OnStepOnceClockwise(e.GetModifiers() == wxMOD_SHIFT);
1191            } else {
1192                OnShiftDisplayRight(e.GetModifiers() == wxMOD_SHIFT);
1193            }
1194            break;
1195        case WXK_UP:
1196            if ((e.GetModifiers() &~ wxMOD_SHIFT) == wxMOD_CONTROL) {
1197                if (m_View->CanRaiseViewpoint() && !m_View->IsExtendedElevation())
1198                    OnHigherViewpoint(e.GetModifiers() == wxMOD_SHIFT);
1199            } else {
1200                OnShiftDisplayUp(e.GetModifiers() == wxMOD_SHIFT);
1201            }
1202            break;
1203        case WXK_DOWN:
1204            if ((e.GetModifiers() &~ wxMOD_SHIFT) == wxMOD_CONTROL) {
1205                if (m_View->CanLowerViewpoint() && !m_View->IsExtendedElevation())
1206                    OnLowerViewpoint(e.GetModifiers() == wxMOD_SHIFT);
1207            } else {
1208                OnShiftDisplayDown(e.GetModifiers() == wxMOD_SHIFT);
1209            }
1210            break;
1211        case WXK_ESCAPE:
1212            if (m_View->ShowingMeasuringLine()) {
1213                OnCancelDistLine();
1214            }
1215            break;
1216        case WXK_F5:
1217            m_View->InvalidateAllLists();
1218            m_View->ForceRefresh();
1219            break;
1220        default:
1221            e.Skip();
1222    }
1223
1224    //if (refresh) m_View->ForceRefresh();
1225}
1226
1227void GUIControl::OnViewFullScreenUpdate(wxUpdateUIEvent& cmd)
1228{
1229    cmd.Check(m_View->IsFullScreen());
1230}
1231
1232void GUIControl::OnViewFullScreen()
1233{
1234    m_View->FullScreenMode();
1235}
1236
1237void GUIControl::OnViewBoundingBoxUpdate(wxUpdateUIEvent& cmd)
1238{
1239    cmd.Enable(m_View->HasData());
1240    cmd.Check(m_View->DisplayingBoundingBox());
1241}
1242
1243void GUIControl::OnViewBoundingBox()
1244{
1245    m_View->ToggleBoundingBox();
1246}
Note: See TracBrowser for help on using the repository browser.