source: git/src/guicontrol.cc @ 6adffadf

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereowalls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since 6adffadf was 2a3d328, checked in by Olly Betts <olly@…>, 19 years ago

Don't regenerate the hittest grid every time the mouse moves while
animating, which solves the mysterious pausing effect (thanks for
spotting this Martin!) Also clear all the status bar coordinates when
animating.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@2873 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 24.8 KB
RevLine 
[56da40e]1//
2//  guicontrol.cc
3//
4//  Handlers for events relating to the display of a survey.
5//
6//  Copyright (C) 2000-2002 Mark R. Shinwell
[2a3d328]7//  Copyright (C) 2001,2003,2004,2005 Olly Betts
[56da40e]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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22//
23
[cbfa50d]24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
[56da40e]28#include "guicontrol.h"
29#include "gfxcore.h"
30#include <wx/confbase.h>
31
[0c7bb77]32const int DISPLAY_SHIFT = 10;
[d6a5001]33const double FLYFREE_SHIFT = 0.2;
[e577f89]34const double ROTATE_STEP = 2.0;
[56da40e]35
36GUIControl::GUIControl()
[82c85aa]37    : dragging(NO_DRAG)
[56da40e]38{
39    m_View = NULL;
40    m_ReverseControls = false;
41    m_LastDrag = drag_NONE;
42}
43
44GUIControl::~GUIControl()
45{
46    // no action
47}
48
49void GUIControl::SetView(GfxCore* view)
50{
51    m_View = view;
52}
53
54bool GUIControl::MouseDown()
55{
[82c85aa]56    return (dragging != NO_DRAG);
[56da40e]57}
58
59void GUIControl::HandleTilt(wxPoint point)
60{
61    // Handle a mouse movement during tilt mode.
62    int dy = point.y - m_DragStart.y;
63
[d877aa2]64    if (m_ReverseControls != m_View->GetPerspective()) dy = -dy;
[56da40e]65
[e577f89]66    m_View->TiltCave(Double(-dy) * 0.36);
[56da40e]67
68    m_DragStart = point;
69
70    m_View->ForceRefresh();
71}
72
73void GUIControl::HandleTranslate(wxPoint point)
74{
75    // Handle a mouse movement during translation mode.
76    int dx = point.x - m_DragStart.x;
77    int dy = point.y - m_DragStart.y;
[096e56c]78
[56da40e]79    if (m_ReverseControls) {
80        dx = -dx;
81        dy = -dy;
82    }
83
[d877aa2]84    if (m_View->GetPerspective())
85        m_View->MoveViewer(0, -dy * .1, dx * .1);
86    else
87        m_View->TranslateCave(dx, dy);
88
[56da40e]89    m_DragStart = point;
90}
91
[dde4fe7]92void GUIControl::HandleScale(wxPoint point)
93{
94    // Handle a mouse movement during scale mode.
95
96    int dx = point.x - m_DragStart.x;
97    int dy = point.y - m_DragStart.y;
98
99    if (m_ReverseControls) {
100        dx = -dx;
101        dy = -dy;
102    }
103
[d877aa2]104    if (m_View->GetPerspective()) {
105        m_View->MoveViewer(-dy * .1, 0, 0);
106    } else {
107        m_View->SetScale(m_View->GetScale() * pow(1.06, 0.08 * dy));
108        m_View->ForceRefresh();
109    }
[dde4fe7]110
111    m_DragStart = point;
112}
113
114void GUIControl::HandleTiltRotate(wxPoint point)
115{
116    // Handle a mouse movement during tilt/rotate mode.
117
118    int dx = point.x - m_DragStart.x;
119    int dy = point.y - m_DragStart.y;
120
[d877aa2]121    if (m_ReverseControls != m_View->GetPerspective()) {
[dde4fe7]122        dx = -dx;
123        dy = -dy;
124    }
125
[e577f89]126    // left/right => rotate, up/down => tilt.
127    // Make tilt less sensitive than rotate as that feels better.
128    m_View->TurnCave(m_View->CanRotate() ? (Double(dx) * -0.36) : 0.0);
129    m_View->TiltCave(Double(-dy) * 0.18);
[dde4fe7]130
131    m_View->ForceRefresh();
132
133    m_DragStart = point;
134}
135
136void GUIControl::HandleScaleRotate(wxPoint point)
[56da40e]137{
138    // Handle a mouse movement during scale/rotate mode.
139    int dx = point.x - m_DragStart.x;
140    int dy = point.y - m_DragStart.y;
141
142    if (m_ReverseControls) {
143        dx = -dx;
144        dy = -dy;
145    }
146
[e577f89]147    Double pan_angle = m_View->CanRotate() ? (Double(dx) * -0.36) : 0.0;
[56da40e]148
149    // left/right => rotate, up/down => scale
150    m_View->TurnCave(pan_angle);
151
[dde4fe7]152    m_View->SetScale(m_View->GetScale() * pow(1.06, 0.08 * dy));
[56da40e]153
154#ifdef AVENGL
155    //glDeleteLists(m_Lists.grid, 1);
156    //    DrawGrid();
157#endif
158    m_View->ForceRefresh();
159
160    m_DragStart = point;
161}
162
[203d2a7]163void GUIControl::HandCursor()
164{
165    const wxCursor HAND_CURSOR(wxCURSOR_HAND);
166    m_View->SetCursor(HAND_CURSOR);
167}
168
169void GUIControl::RestoreCursor()
170{
171    if (m_View->ShowingMeasuringLine()) {
172        HandCursor();
[096e56c]173    } else {
[203d2a7]174        m_View->SetCursor(wxNullCursor);
175    }
176}
177
[56da40e]178//
179//  Mouse event handling methods
180//
181
182void GUIControl::OnMouseMove(wxMouseEvent& event)
183{
184    // Mouse motion event handler.
185    if (!m_View->HasData()) return;
186
[2a3d328]187    // If we're animating, don't show mouse coordinates or the nearest
188    // station.
189    if (m_View->Animating()) return;
190
[56da40e]191    wxPoint point = wxPoint(event.GetX(), event.GetY());
192
193    // Check hit-test grid (only if no buttons are pressed).
194    if (!event.LeftIsDown() && !event.MiddleIsDown() && !event.RightIsDown()) {
[203d2a7]195        if (m_View->CheckHitTestGrid(point, false)) {
196            HandCursor();
[096e56c]197        } else {
[203d2a7]198            if (m_View->ShowingScaleBar() &&
199                m_View->PointWithinScaleBar(point)) {
200
201                const wxCursor CURSOR(wxCURSOR_SIZEWE);
202                m_View->SetCursor(CURSOR);
[096e56c]203            } else {
[203d2a7]204                m_View->SetCursor(wxNullCursor);
205            }
206        }
[56da40e]207    }
208
[203d2a7]209    // Update coordinate display if in plan view,
210    // or altitude if in elevation view.
[56da40e]211    m_View->SetCoords(point);
212
[2a3d328]213    switch (dragging) {
214        case LEFT_DRAG:
215            if (m_LastDrag == drag_NONE) {
216                if (m_View->ShowingCompass() &&
217                    m_View->PointWithinCompass(point)) {
218                    m_LastDrag = drag_COMPASS;
219                } else if (m_View->ShowingClino() &&
220                           m_View->PointWithinClino(point)) {
221                    m_LastDrag = drag_ELEV;
222                } else if (m_View->ShowingScaleBar() &&
223                           m_View->PointWithinScaleBar(point)) {
224                    m_LastDrag = drag_SCALE;
[82c85aa]225                }
[2a3d328]226            }
227
228            if (m_LastDrag == drag_COMPASS) {
229                // drag in heading indicator
230                m_View->SetCompassFromPoint(point);
231            } else if (m_LastDrag == drag_ELEV) {
232                // drag in clinometer
233                m_View->SetClinoFromPoint(point);
234            } else if (m_LastDrag == drag_SCALE) {
235                // FIXME: check why there was a check here for x being inside
236                // the window
237                m_View->SetScaleBarFromOffset(point.x - m_DragLast.x);
238            } else if (m_LastDrag == drag_NONE || m_LastDrag == drag_MAIN) {
239                m_LastDrag = drag_MAIN;
[82c85aa]240                if (event.ShiftDown()) {
[2a3d328]241                    HandleScaleRotate(point);
[82c85aa]242                } else {
[2a3d328]243                    HandleTiltRotate(point);
[82c85aa]244                }
[2a3d328]245            }
246            break;
247        case MIDDLE_DRAG:
248            if (event.ShiftDown()) {
249                HandleTilt(point);
250            } else {
251                HandleScale(point);
252            }
253            break;
254        case RIGHT_DRAG:
255            if ((m_LastDrag == drag_NONE && m_View->PointWithinScaleBar(point)) || m_LastDrag == drag_SCALE) {
256            /* FIXME
257                  if (point.x < 0) point.x = 0;
258                  if (point.y < 0) point.y = 0;
259                  if (point.x > m_XSize) point.x = m_XSize;
260                  if (point.y > m_YSize) point.y = m_YSize;
261                  m_LastDrag = drag_SCALE;
262                  int x_inside_bar = m_DragStart.x - m_ScaleBar.drag_start_offset_x;
263                  int y_inside_bar = m_YSize - m_ScaleBar.drag_start_offset_y - m_DragStart.y;
264                  m_ScaleBar.offset_x = point.x - x_inside_bar;
265                  m_ScaleBar.offset_y = (m_YSize - point.y) - y_inside_bar;
266                  m_View->ForceRefresh(); */
267            } else {
268                m_LastDrag = drag_MAIN;
269                HandleTranslate(point);
270            }
271            break;
272        case NO_DRAG:
273            break;
[56da40e]274    }
275
276    m_DragLast = point;
277}
278
279void GUIControl::OnLButtonDown(wxMouseEvent& event)
280{
281    if (m_View->HasData() && m_View->GetLock() != lock_POINT) {
[82c85aa]282        dragging = LEFT_DRAG;
[096e56c]283
[56da40e]284        /* FIXME
285        m_ScaleBar.drag_start_offset_x = m_ScaleBar.offset_x;
286        m_ScaleBar.drag_start_offset_y = m_ScaleBar.offset_y; */
287
288        m_DragStart = m_DragRealStart = wxPoint(event.GetX(), event.GetY());
[096e56c]289
[203d2a7]290//        const wxCursor CURSOR(wxCURSOR_MAGNIFIER);
291//        m_View->SetCursor(CURSOR);
[56da40e]292        m_View->CaptureMouse();
293    }
294}
295
296void GUIControl::OnLButtonUp(wxMouseEvent& event)
297{
298    if (m_View->HasData() && m_View->GetLock() != lock_POINT) {
299        if (event.GetPosition() == m_DragRealStart) {
300            // just a "click"...
301            m_View->CheckHitTestGrid(m_DragStart, true);
302        }
303
[dde4fe7]304//      m_View->RedrawIndicators();
[56da40e]305        m_View->ReleaseMouse();
306
307        m_LastDrag = drag_NONE;
[82c85aa]308        dragging = NO_DRAG;
[56da40e]309
310        m_View->DragFinished();
[096e56c]311
[203d2a7]312        RestoreCursor();
[56da40e]313    }
314}
315
316void GUIControl::OnMButtonDown(wxMouseEvent& event)
317{
318    if (m_View->HasData() && m_View->GetLock() == lock_NONE) {
[82c85aa]319        dragging = MIDDLE_DRAG;
[56da40e]320        m_DragStart = wxPoint(event.GetX(), event.GetY());
321
[dde4fe7]322        const wxCursor CURSOR(wxCURSOR_MAGNIFIER);
[203d2a7]323        m_View->SetCursor(CURSOR);
[56da40e]324        m_View->CaptureMouse();
325    }
326}
327
[cc2a5fc]328void GUIControl::OnMButtonUp(wxMouseEvent&)
[56da40e]329{
330    if (m_View->HasData() && m_View->GetLock() == lock_NONE) {
[82c85aa]331        dragging = NO_DRAG;
[56da40e]332        m_View->ReleaseMouse();
333        m_View->DragFinished();
[203d2a7]334
335        RestoreCursor();
[56da40e]336    }
337}
338
339void GUIControl::OnRButtonDown(wxMouseEvent& event)
340{
341    if (m_View->HasData()) {
342        m_DragStart = wxPoint(event.GetX(), event.GetY());
[096e56c]343
[56da40e]344/* FIXME        m_ScaleBar.drag_start_offset_x = m_ScaleBar.offset_x;
345        m_ScaleBar.drag_start_offset_y = m_ScaleBar.offset_y; */
346
[82c85aa]347        dragging = RIGHT_DRAG;
[56da40e]348
[203d2a7]349      //  const wxCursor CURSOR(wxCURSOR_HAND);
350      //  m_View->SetCursor(CURSOR);
[56da40e]351        m_View->CaptureMouse();
352    }
353}
354
[cc2a5fc]355void GUIControl::OnRButtonUp(wxMouseEvent&)
[56da40e]356{
357    m_LastDrag = drag_NONE;
358    m_View->ReleaseMouse();
359
[82c85aa]360    dragging = NO_DRAG;
[096e56c]361
[203d2a7]362    RestoreCursor();
[096e56c]363
[56da40e]364    m_View->DragFinished();
365}
366
[34d8d1a]367void GUIControl::OnMouseWheel(wxMouseEvent& event) {
368    m_View->TiltCave(event.GetWheelRotation() / 24.0);
369    m_View->ForceRefresh();
370}
371
[56da40e]372void GUIControl::OnDisplayOverlappingNames()
373{
374    m_View->ToggleOverlappingNames();
375}
376
377void GUIControl::OnDisplayOverlappingNamesUpdate(wxUpdateUIEvent& cmd)
378{
379    cmd.Enable(m_View->HasData() && m_View->ShowingStationNames());
380    cmd.Check(m_View->ShowingOverlappingNames());
381}
382
[da6c802]383void GUIControl::OnColourByDepth()
384{
385    if (m_View->ColouringBy() == COLOUR_BY_DEPTH) {
386        m_View->SetColourBy(COLOUR_BY_NONE);
387    } else {
388        m_View->SetColourBy(COLOUR_BY_DEPTH);
389    }
390}
391
392void GUIControl::OnColourByDepthUpdate(wxUpdateUIEvent& cmd)
393{
394    cmd.Enable(m_View->HasData() && m_View->HasUndergroundLegs());
395    cmd.Check(m_View->ColouringBy() == COLOUR_BY_DEPTH);
396}
397
[56da40e]398void GUIControl::OnShowCrosses()
399{
400    m_View->ToggleCrosses();
401}
402
403void GUIControl::OnShowCrossesUpdate(wxUpdateUIEvent& cmd)
404{
405    cmd.Enable(m_View->HasData());
406    cmd.Check(m_View->ShowingCrosses());
407}
408
409void GUIControl::OnShowStationNames()
410{
411    m_View->ToggleStationNames();
412}
413
414void GUIControl::OnShowStationNamesUpdate(wxUpdateUIEvent& cmd)
415{
416    cmd.Enable(m_View->HasData());
417    cmd.Check(m_View->ShowingStationNames());
418}
419
420void GUIControl::OnShowSurveyLegs()
421{
422    m_View->ToggleUndergroundLegs();
423}
424
425void GUIControl::OnShowSurveyLegsUpdate(wxUpdateUIEvent& cmd)
426{
427    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT && m_View->HasUndergroundLegs());
428    cmd.Check(m_View->ShowingUndergroundLegs());
429}
430
431void GUIControl::OnMoveEast()
432{
[e577f89]433    m_View->TurnCaveTo(90.0);
[56da40e]434    m_View->ForceRefresh();
435}
436
437void GUIControl::OnMoveEastUpdate(wxUpdateUIEvent& cmd)
438{
439    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_Y));
440}
441
442void GUIControl::OnMoveNorth()
443{
444    m_View->TurnCaveTo(0.0);
445    m_View->ForceRefresh();
446}
447
448void GUIControl::OnMoveNorthUpdate(wxUpdateUIEvent& cmd)
449{
450    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_X));
451}
452
453void GUIControl::OnMoveSouth()
454{
[e577f89]455    m_View->TurnCaveTo(180.0);
[56da40e]456    m_View->ForceRefresh();
457}
458
459void GUIControl::OnMoveSouthUpdate(wxUpdateUIEvent& cmd)
460{
461    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_X));
462}
463
464void GUIControl::OnMoveWest()
465{
[e577f89]466    m_View->TurnCaveTo(270.0);
[56da40e]467    m_View->ForceRefresh();
468}
469
470void GUIControl::OnMoveWestUpdate(wxUpdateUIEvent& cmd)
471{
472    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_Y));
473}
474
475void GUIControl::OnStartRotation()
476{
477    m_View->StartRotation();
478}
479
480void GUIControl::OnStartRotationUpdate(wxUpdateUIEvent& cmd)
481{
482    cmd.Enable(m_View->HasData() && !m_View->IsRotating() && m_View->CanRotate());
483}
484
485void GUIControl::OnToggleRotation()
486{
487    m_View->ToggleRotation();
488}
489
490void GUIControl::OnToggleRotationUpdate(wxUpdateUIEvent& cmd)
491{
492    cmd.Enable(m_View->HasData() && m_View->CanRotate());
493    cmd.Check(m_View->HasData() && m_View->IsRotating());
494}
495
496void GUIControl::OnStopRotation()
497{
498    m_View->StopRotation();
499}
500
501void GUIControl::OnStopRotationUpdate(wxUpdateUIEvent& cmd)
502{
503    cmd.Enable(m_View->HasData() && m_View->IsRotating());
504}
505
506void GUIControl::OnReverseControls()
507{
508    m_ReverseControls = !m_ReverseControls;
509}
510
511void GUIControl::OnReverseControlsUpdate(wxUpdateUIEvent& cmd)
512{
513    cmd.Enable(m_View->HasData());
514    cmd.Check(m_ReverseControls);
515}
516
517void GUIControl::OnReverseDirectionOfRotation()
518{
519    m_View->ReverseRotation();
520}
521
522void GUIControl::OnReverseDirectionOfRotationUpdate(wxUpdateUIEvent& cmd)
523{
524    cmd.Enable(m_View->HasData() && m_View->CanRotate());
525}
526
527void GUIControl::OnSlowDown(bool accel)
528{
529    m_View->RotateSlower(accel);
530}
531
532void GUIControl::OnSlowDownUpdate(wxUpdateUIEvent& cmd)
533{
534    cmd.Enable(m_View->HasData() && m_View->CanRotate());
535}
536
537void GUIControl::OnSpeedUp(bool accel)
538{
539    m_View->RotateFaster(accel);
540}
541
542void GUIControl::OnSpeedUpUpdate(wxUpdateUIEvent& cmd)
543{
544    cmd.Enable(m_View->HasData() && m_View->CanRotate());
545}
546
547void GUIControl::OnStepOnceAnticlockwise(bool accel)
548{
[d877aa2]549    if (m_View->GetPerspective()) {
550        m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
551    } else {
552        m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
553    }
[56da40e]554    m_View->ForceRefresh();
555}
556
557void GUIControl::OnStepOnceAnticlockwiseUpdate(wxUpdateUIEvent& cmd)
558{
559    cmd.Enable(m_View->HasData() && m_View->CanRotate() && !m_View->IsRotating());
560}
561
562void GUIControl::OnStepOnceClockwise(bool accel)
563{
[d877aa2]564    if (m_View->GetPerspective()) {
565        m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
566    } else {
567        m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
568    }
[56da40e]569    m_View->ForceRefresh();
570}
571
572void GUIControl::OnStepOnceClockwiseUpdate(wxUpdateUIEvent& cmd)
573{
574    cmd.Enable(m_View->HasData() && m_View->CanRotate() && !m_View->IsRotating());
575}
576
577void GUIControl::OnDefaults()
578{
579    m_View->Defaults();
580}
581
582void GUIControl::OnDefaultsUpdate(wxUpdateUIEvent& cmd)
583{
584    cmd.Enable(m_View->HasData());
585}
586
587void GUIControl::OnElevation()
588{
589    // Switch to elevation view.
590
591    m_View->SwitchToElevation();
592}
593
594void GUIControl::OnElevationUpdate(wxUpdateUIEvent& cmd)
595{
596    cmd.Enable(m_View->HasData() && m_View->GetLock() == lock_NONE && !m_View->ShowingElevation());
597}
598
599void GUIControl::OnHigherViewpoint(bool accel)
600{
601    // Raise the viewpoint.
[d877aa2]602    if (m_View->GetPerspective()) {
603        m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
604    } else {
605        m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
606    }
[56da40e]607    m_View->ForceRefresh();
608}
609
610void GUIControl::OnHigherViewpointUpdate(wxUpdateUIEvent& cmd)
611{
[0662b0b]612    cmd.Enable(m_View->HasData() && m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE);
[56da40e]613}
614
615void GUIControl::OnLowerViewpoint(bool accel)
616{
617    // Lower the viewpoint.
[d877aa2]618    if (m_View->GetPerspective()) {
619        m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
620    } else {
621        m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
622    }
[d6a5001]623    m_View->ForceRefresh();
[56da40e]624}
625
626void GUIControl::OnLowerViewpointUpdate(wxUpdateUIEvent& cmd)
627{
[0662b0b]628    cmd.Enable(m_View->HasData() && m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE);
[56da40e]629}
630
631void GUIControl::OnPlan()
632{
633    // Switch to plan view.
634    m_View->SwitchToPlan();
635}
636
637void GUIControl::OnPlanUpdate(wxUpdateUIEvent& cmd)
638{
639    cmd.Enable(m_View->HasData() && m_View->GetLock() == lock_NONE && !m_View->ShowingPlan());
640}
641
642void GUIControl::OnShiftDisplayDown(bool accel)
643{
[096e56c]644    if (m_View->GetPerspective())
[867a1141]645        m_View->MoveViewer(0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0);
[d877aa2]646    else
647        m_View->TranslateCave(0, accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT);
[56da40e]648}
649
650void GUIControl::OnShiftDisplayDownUpdate(wxUpdateUIEvent& cmd)
651{
652    cmd.Enable(m_View->HasData());
653}
654
655void GUIControl::OnShiftDisplayLeft(bool accel)
656{
[096e56c]657    if (m_View->GetPerspective())
[867a1141]658        m_View->MoveViewer(0, 0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT);
[d877aa2]659    else
660        m_View->TranslateCave(accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT, 0);
[56da40e]661}
662
663void GUIControl::OnShiftDisplayLeftUpdate(wxUpdateUIEvent& cmd)
664{
665    cmd.Enable(m_View->HasData());
666}
667
668void GUIControl::OnShiftDisplayRight(bool accel)
669{
[096e56c]670    if (m_View->GetPerspective())
[867a1141]671        m_View->MoveViewer(0, 0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT);
[d877aa2]672    else
673        m_View->TranslateCave(accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT, 0);
[56da40e]674}
675
676void GUIControl::OnShiftDisplayRightUpdate(wxUpdateUIEvent& cmd)
677{
678    cmd.Enable(m_View->HasData());
679}
680
681void GUIControl::OnShiftDisplayUp(bool accel)
682{
[096e56c]683    if (m_View->GetPerspective())
[867a1141]684        m_View->MoveViewer(0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0);
[d877aa2]685    else
686        m_View->TranslateCave(0, accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT);
[56da40e]687}
688
689void GUIControl::OnShiftDisplayUpUpdate(wxUpdateUIEvent& cmd)
690{
691    cmd.Enable(m_View->HasData());
692}
693
694void GUIControl::OnZoomIn(bool accel)
695{
696    // Increase the scale.
697
[d877aa2]698    if (m_View->GetPerspective()) {
699        m_View->MoveViewer(accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0, 0);
700    } else {
701        m_View->SetScale(m_View->GetScale() * (accel ? 1.1236 : 1.06));
702        m_View->ForceRefresh();
703    }
[56da40e]704}
705
706void GUIControl::OnZoomInUpdate(wxUpdateUIEvent& cmd)
707{
708    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT);
709}
710
711void GUIControl::OnZoomOut(bool accel)
712{
713    // Decrease the scale.
714
[d877aa2]715    if (m_View->GetPerspective()) {
716        m_View->MoveViewer(accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0, 0);
717    } else {
718        m_View->SetScale(m_View->GetScale() / (accel ? 1.1236 : 1.06));
719        m_View->ForceRefresh();
720    }
[56da40e]721}
722
723void GUIControl::OnZoomOutUpdate(wxUpdateUIEvent& cmd)
724{
725    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT);
726}
727
728void GUIControl::OnToggleScalebar()
729{
730    m_View->ToggleScaleBar();
731}
732
733void GUIControl::OnToggleScalebarUpdate(wxUpdateUIEvent& cmd)
734{
735    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT);
736    cmd.Check(m_View->ShowingScaleBar());
737}
738
739void GUIControl::OnToggleDepthbar() /* FIXME naming */
740{
741    m_View->ToggleDepthBar();
742}
743
744void GUIControl::OnToggleDepthbarUpdate(wxUpdateUIEvent& cmd)
745{
[da6c802]746    cmd.Enable(m_View->HasData() && !(m_View->GetLock() && lock_Z) &&
747               m_View->ColouringBy() == COLOUR_BY_DEPTH);
[56da40e]748    cmd.Check(m_View->ShowingDepthBar());
749}
750
751void GUIControl::OnViewCompass()
752{
753    m_View->ToggleCompass();
754}
755
756void GUIControl::OnViewCompassUpdate(wxUpdateUIEvent& cmd)
757{
758    cmd.Enable(m_View->HasData() && m_View->CanRotate());
759    cmd.Check(m_View->ShowingCompass());
760}
761
762void GUIControl::OnViewClino()
763{
764    m_View->ToggleClino();
765}
766
767void GUIControl::OnViewClinoUpdate(wxUpdateUIEvent& cmd)
768{
769    cmd.Enable(m_View->HasData() && m_View->GetLock() == lock_NONE);
770    cmd.Check(m_View->ShowingClino());
771}
772
773void GUIControl::OnShowSurface()
774{
775    m_View->ToggleSurfaceLegs();
776}
777
778void GUIControl::OnShowSurfaceUpdate(wxUpdateUIEvent& cmd)
779{
780    cmd.Enable(m_View->HasData() && m_View->HasSurfaceLegs());
781    cmd.Check(m_View->ShowingSurfaceLegs());
782}
783
784void GUIControl::OnShowEntrances()
785{
786    m_View->ToggleEntrances();
787}
788
789void GUIControl::OnShowEntrancesUpdate(wxUpdateUIEvent& cmd)
790{
791    cmd.Enable(m_View->HasData() && (m_View->GetNumEntrances() > 0));
792    cmd.Check(m_View->ShowingEntrances());
793}
794
795void GUIControl::OnShowFixedPts()
796{
797    m_View->ToggleFixedPts();
798}
799
800void GUIControl::OnShowFixedPtsUpdate(wxUpdateUIEvent& cmd)
801{
802    cmd.Enable(m_View->HasData() && (m_View->GetNumFixedPts() > 0));
803    cmd.Check(m_View->ShowingFixedPts());
804}
805
806void GUIControl::OnShowExportedPts()
807{
808    m_View->ToggleExportedPts();
809}
810
811void GUIControl::OnShowExportedPtsUpdate(wxUpdateUIEvent& cmd)
812{
[d877aa2]813    // FIXME enable only if we have timestamps...
814    cmd.Enable(m_View->HasData() /*&& (m_View->GetNumExportedPts() > 0)*/);
[56da40e]815    cmd.Check(m_View->ShowingExportedPts());
816}
817
818void GUIControl::OnViewGrid()
819{
820    m_View->ToggleGrid();
821}
822
823void GUIControl::OnViewGridUpdate(wxUpdateUIEvent& cmd)
824{
825    cmd.Enable(m_View->HasData());
[0580c6a]826    cmd.Check(m_View->ShowingGrid());
[56da40e]827}
828
829void GUIControl::OnIndicatorsUpdate(wxUpdateUIEvent& cmd)
830{
831    cmd.Enable(m_View->HasData());
832}
833
[6abab84]834void GUIControl::OnViewPerspective()
835{
836    m_View->TogglePerspective();
[d877aa2]837    // Force update of coordinate display.
838    if (m_View->GetPerspective()) {
839        m_View->MoveViewer(0, 0, 0);
840    } else {
841        m_View->ClearCoords();
842    }
[6abab84]843}
844
845void GUIControl::OnViewPerspectiveUpdate(wxUpdateUIEvent& cmd)
846{
847    cmd.Enable(m_View->HasData());
848    cmd.Check(m_View->GetPerspective());
849}
850
[a517825]851void GUIControl::OnViewTextured()
852{
853    m_View->ToggleTextured();
854}
855
856void GUIControl::OnViewTexturedUpdate(wxUpdateUIEvent& cmd)
857{
858    cmd.Enable(m_View->HasData());
859    cmd.Check(m_View->GetTextured());
860}
861
[c60062d]862void GUIControl::OnViewFog()
863{
864    m_View->ToggleFog();
865}
866
867void GUIControl::OnViewFogUpdate(wxUpdateUIEvent& cmd)
868{
869    cmd.Enable(m_View->HasData());
870    cmd.Check(m_View->GetFog());
871}
872
[db452ae]873void GUIControl::OnViewSmoothLines()
874{
875    m_View->ToggleAntiAlias();
876}
877
878void GUIControl::OnViewSmoothLinesUpdate(wxUpdateUIEvent& cmd)
879{
880    cmd.Enable(m_View->HasData());
881    cmd.Check(m_View->GetAntiAlias());
882}
883
[56da40e]884void GUIControl::OnToggleMetric()
885{
886    m_View->ToggleMetric();
887
888    wxConfigBase::Get()->Write("metric", m_View->GetMetric());
889    wxConfigBase::Get()->Flush();
890}
891
892void GUIControl::OnToggleMetricUpdate(wxUpdateUIEvent& cmd)
893{
894    cmd.Enable(m_View->HasData());
895    cmd.Check(m_View->GetMetric());
896}
897
898void GUIControl::OnToggleDegrees()
899{
900    m_View->ToggleDegrees();
[096e56c]901
[56da40e]902    wxConfigBase::Get()->Write("degrees", m_View->GetDegrees());
903    wxConfigBase::Get()->Flush();
904}
905
906void GUIControl::OnToggleDegreesUpdate(wxUpdateUIEvent& cmd)
907{
908    cmd.Enable(m_View->HasData());
909    cmd.Check(m_View->GetDegrees());
910}
911
912void GUIControl::OnToggleTubes()
913{
914    m_View->ToggleTubes();
915}
916
917void GUIControl::OnToggleTubesUpdate(wxUpdateUIEvent& cmd)
918{
919    cmd.Enable(m_View->HasData());
920    cmd.Check(m_View->GetTubes());
921}
922
923void GUIControl::OnCancelDistLine()
924{
925    m_View->ClearTreeSelection();
926}
927
928void GUIControl::OnCancelDistLineUpdate(wxUpdateUIEvent& cmd)
929{
930    cmd.Enable(m_View->ShowingMeasuringLine());
931}
932
933void GUIControl::OnKeyPress(wxKeyEvent &e)
934{
935    if (!m_View->HasData()) {
936        e.Skip();
937        return;
938    }
939
[1690fa9]940    // The changelog says this is meant to keep animation going while keys are
941    // pressed, but that happens anyway (on linux at least - perhaps it helps
942    // on windows?)  FIXME : check!
943    //bool refresh = m_View->Animate();
[56da40e]944
945    switch (e.m_keyCode) {
946        case '/': case '?':
947            if (m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE)
948                OnLowerViewpoint(e.m_shiftDown);
949            break;
950        case '\'': case '@': case '"': // both shifted forms - US and UK kbd
951            if (m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE)
952                OnHigherViewpoint(e.m_shiftDown);
953            break;
954        case 'C': case 'c':
955            if (m_View->CanRotate() && !m_View->IsRotating())
956                OnStepOnceAnticlockwise(e.m_shiftDown);
957            break;
958        case 'V': case 'v':
959            if (m_View->CanRotate() && !m_View->IsRotating())
960                OnStepOnceClockwise(e.m_shiftDown);
961            break;
962        case ']': case '}':
963            if (m_View->GetLock() != lock_POINT)
964                OnZoomIn(e.m_shiftDown);
965            break;
966        case '[': case '{':
967            if (m_View->GetLock() != lock_POINT)
968                OnZoomOut(e.m_shiftDown);
969            break;
970        case 'N': case 'n':
971            if (!(m_View->GetLock() & lock_X))
972                OnMoveNorth();
973            break;
974        case 'S': case 's':
975            if (!(m_View->GetLock() & lock_X))
976                OnMoveSouth();
977            break;
978        case 'E': case 'e':
979            if (!(m_View->GetLock() & lock_Y))
980                OnMoveEast();
981            break;
982        case 'W': case 'w':
983            if (!(m_View->GetLock() & lock_Y))
984                OnMoveWest();
985            break;
986        case 'Z': case 'z':
987            if (m_View->CanRotate())
988                OnSpeedUp(e.m_shiftDown);
989            break;
990        case 'X': case 'x':
991            if (m_View->CanRotate())
992                OnSlowDown(e.m_shiftDown);
993            break;
994        case 'R': case 'r':
995            if (m_View->CanRotate())
996                OnReverseDirectionOfRotation();
997            break;
998        case 'P': case 'p':
999            if (m_View->GetLock() == lock_NONE && !m_View->ShowingPlan())
1000                OnPlan();
1001            break;
1002        case 'L': case 'l':
1003            if (m_View->GetLock() == lock_NONE && !m_View->ShowingElevation())
1004                OnElevation();
1005            break;
1006        case 'O': case 'o':
1007            OnDisplayOverlappingNames();
1008            break;
1009        case WXK_DELETE:
1010            OnDefaults();
1011            break;
1012        case WXK_RETURN:
1013            if (m_View->CanRotate() && !m_View->IsRotating())
1014                OnStartRotation();
1015            break;
1016        case WXK_SPACE:
1017            if (m_View->IsRotating())
1018                OnStopRotation();
1019            break;
1020        case WXK_LEFT:
1021            if (e.m_controlDown) {
1022                if (m_View->CanRotate() && !m_View->IsRotating())
1023                    OnStepOnceAnticlockwise(e.m_shiftDown);
1024            } else {
1025                OnShiftDisplayLeft(e.m_shiftDown);
1026            }
1027            break;
1028        case WXK_RIGHT:
1029            if (e.m_controlDown) {
1030                if (m_View->CanRotate() && !m_View->IsRotating())
1031                    OnStepOnceClockwise(e.m_shiftDown);
1032            } else {
1033                OnShiftDisplayRight(e.m_shiftDown);
1034            }
1035            break;
1036        case WXK_UP:
1037            if (e.m_controlDown) {
1038                if (m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE)
1039                    OnHigherViewpoint(e.m_shiftDown);
1040            } else {
1041                OnShiftDisplayUp(e.m_shiftDown);
1042            }
1043            break;
1044        case WXK_DOWN:
1045            if (e.m_controlDown) {
1046                if (m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE)
1047                    OnLowerViewpoint(e.m_shiftDown);
1048            } else {
1049                OnShiftDisplayDown(e.m_shiftDown);
1050            }
1051            break;
1052        case WXK_ESCAPE:
1053            if (m_View->ShowingMeasuringLine()) {
1054                OnCancelDistLine();
1055            }
1056            break;
1057        default:
1058            e.Skip();
1059    }
[096e56c]1060
[1690fa9]1061    //if (refresh) m_View->ForceRefresh();
[56da40e]1062}
1063
[b13aee4]1064void GUIControl::OnViewFullScreenUpdate(wxUpdateUIEvent& cmd)
1065{
1066    cmd.Enable(m_View->HasData());
[fdfa926]1067    cmd.Check(m_View->IsFullScreen());
[b13aee4]1068}
1069
1070void GUIControl::OnViewFullScreen()
1071{
1072    m_View->FullScreenMode();
1073}
Note: See TracBrowser for help on using the repository browser.