source: git/src/gfxcore.h @ 6987d2a

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

src/gfxcore.cc,src/gfxcore.h: Reimplement animation so that it's
based on angular change per unit of elapsed time, rather than
averaging the time take for the last two scene redraws. This gives
a more even animation in the face of variable load and scene redraw
time, and should be more consistent between platforms.
src/gfxcore.cc: Switch to a point of the compass during auto-rotation
now jumps straight there rather than the two animations fighting.
src/gfxcore.cc: Reduce the maximum auto-rotation speed, as the
previous limit was uselessly fast.

  • Property mode set to 100644
File size: 15.2 KB
Line 
1//
2//  gfxcore.h
3//
4//  Core drawing code for Aven.
5//
6//  Copyright (C) 2000-2001,2002,2005 Mark R. Shinwell.
7//  Copyright (C) 2001-2004,2005,2006,2007,2010,2011,2012,2013,2014,2017 Olly Betts
8//  Copyright (C) 2005 Martin Green
9//
10//  This program is free software; you can redistribute it and/or modify
11//  it under the terms of the GNU General Public License as published by
12//  the Free Software Foundation; either version 2 of the License, or
13//  (at your option) any later version.
14//
15//  This program is distributed in the hope that it will be useful,
16//  but WITHOUT ANY WARRANTY; without even the implied warranty of
17//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18//  GNU General Public License for more details.
19//
20//  You should have received a copy of the GNU General Public License
21//  along with this program; if not, write to the Free Software
22//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23//
24
25#ifndef gfxcore_h
26#define gfxcore_h
27
28#include <float.h>
29#include <limits.h>
30#include <time.h>
31
32#include "img_hosted.h"
33
34#include "guicontrol.h"
35#include "labelinfo.h"
36#include "vector3.h"
37#include "wx.h"
38#include "gla.h"
39
40#include <list>
41#include <utility>
42#include <vector>
43
44using namespace std;
45
46class MainFrm;
47class traverse;
48
49class XSect;
50class PointInfo;
51class MovieMaker;
52
53class PresentationMark : public Point {
54  public:
55    Double angle, tilt_angle;
56    Double scale;
57    Double time;
58    PresentationMark() : Point(), angle(0), tilt_angle(0), scale(0), time(0)
59        { }
60    PresentationMark(const Vector3 & v, Double angle_, Double tilt_angle_,
61                     Double scale_, Double time_ = 0)
62        : Point(v), angle(angle_), tilt_angle(tilt_angle_), scale(scale_),
63          time(time_)
64        { }
65    bool is_valid() const { return scale > 0; }
66};
67
68struct ZoomBox {
69  public:
70    int x1, y1, x2, y2;
71
72    ZoomBox()
73        : x1(INT_MAX) { }
74
75    bool active() const { return x1 != INT_MAX; }
76
77    void set(const wxPoint & p1, const wxPoint & p2) {
78        x1 = p1.x;
79        y1 = p1.y;
80        x2 = p2.x;
81        y2 = p2.y;
82    }
83
84    void unset() {
85        x1 = INT_MAX;
86    }
87};
88
89enum {
90    COLOUR_BY_NONE,
91    COLOUR_BY_DEPTH,
92    COLOUR_BY_DATE,
93    COLOUR_BY_ERROR,
94    COLOUR_BY_LIMIT_ // Leave this last.
95};
96
97enum {
98    UPDATE_NONE,
99    UPDATE_BLOBS,
100    UPDATE_BLOBS_AND_CROSSES
101};
102
103enum {
104      SPLAYS_HIDE,
105      SPLAYS_SHOW_FADED,
106      SPLAYS_SHOW_NORMAL,
107};
108
109class GfxCore : public GLACanvas {
110    Double m_Scale;
111    int m_ScaleBarWidth;
112
113    typedef enum {
114        LIST_COMPASS,
115        LIST_CLINO,
116        LIST_CLINO_BACK,
117        LIST_SCALE_BAR,
118        LIST_DEPTH_KEY,
119        LIST_DATE_KEY,
120        LIST_ERROR_KEY,
121        LIST_UNDERGROUND_LEGS,
122        LIST_TUBES,
123        LIST_SURFACE_LEGS,
124        LIST_BLOBS,
125        LIST_CROSSES,
126        LIST_GRID,
127        LIST_SHADOW,
128        LIST_LIMIT_ // Leave this last.
129    } drawing_list;
130
131    static const int NUM_COLOUR_BANDS = 13;
132
133    void SetPanBase() {
134        base_pan = m_PanAngle;
135        base_pan_time = timer.Time() - (1000 / 25);
136    }
137
138    void SetTiltBase() {
139        base_tilt = m_TiltAngle;
140        base_tilt_time = timer.Time() - (1000 / 25);
141    }
142
143public:
144    typedef enum {
145        CURSOR_DEFAULT,
146        CURSOR_POINTING_HAND,
147        CURSOR_DRAGGING_HAND,
148        CURSOR_HORIZONTAL_RESIZE,
149        CURSOR_ROTATE_HORIZONTALLY,
150        CURSOR_ROTATE_VERTICALLY,
151        CURSOR_ROTATE_EITHER_WAY,
152        CURSOR_ZOOM,
153        CURSOR_ZOOM_ROTATE
154    } cursor;
155
156private:
157    GUIControl* m_Control;
158    char* m_LabelGrid;
159    MainFrm* m_Parent;
160    bool m_DoneFirstShow;
161    Double m_TiltAngle;
162    Double m_PanAngle;
163    bool m_Rotating;
164    Double m_RotationStep;
165    int m_SwitchingTo;
166    bool m_Crosses;
167    bool m_Legs;
168    int m_Splays;
169    bool m_Names;
170    bool m_Scalebar;
171    bool m_ColourKey;
172    bool m_OverlappingNames;
173    bool m_Compass;
174    bool m_Clino;
175    bool m_Tubes;
176    int m_ColourBy;
177
178    bool m_HaveData;
179    bool m_MouseOutsideCompass;
180    bool m_MouseOutsideElev;
181    bool m_Surface;
182    bool m_Entrances;
183    bool m_FixedPts;
184    bool m_ExportedPts;
185    bool m_Grid;
186    bool m_BoundingBox;
187
188    bool m_Degrees;
189    bool m_Metric;
190    bool m_Percent;
191
192    bool m_HitTestDebug;
193
194    list<LabelInfo*> *m_PointGrid;
195    bool m_HitTestGridValid;
196
197    LabelInfo temp_here;
198    const LabelInfo * m_here;
199    const LabelInfo * m_there;
200
201    wxStopWatch timer;
202    long base_tilt_time;
203    long base_pan_time;
204    Double base_tilt;
205    Double base_pan;
206
207    GLAPen m_Pens[NUM_COLOUR_BANDS + 1];
208
209#define PLAYING 1
210    int presentation_mode; // for now, 0 => off, PLAYING => continuous play
211    bool pres_reverse;
212    double pres_speed;
213    PresentationMark next_mark;
214    double next_mark_time;
215    double this_mark_total;
216
217    MovieMaker * movie;
218
219    cursor current_cursor;
220
221    int sqrd_measure_threshold;
222
223    // The legends for each entry in the colour key.
224    wxString key_legends[NUM_COLOUR_BANDS];
225
226    wxPoint key_lowerleft[COLOUR_BY_LIMIT_];
227
228    ZoomBox zoombox;
229
230    void PlaceVertexWithColour(const Vector3 &v, Double factor = 1.0);
231    void PlaceVertexWithColour(const Vector3 & v, GLint tex_x, GLint tex_y,
232                               Double factor);
233    void SetDepthColour(Double z, Double factor);
234    void PlaceVertexWithDepthColour(const Vector3 & v, Double factor = 1.0);
235    void PlaceVertexWithDepthColour(const Vector3 & v, GLint tex_x, GLint tex_y, Double factor);
236
237    void SetColourFromDate(int date, Double factor);
238    void SetColourFromError(double E, Double factor);
239
240    int GetClinoOffset() const;
241    void DrawTick(int angle_cw);
242    void DrawArrow(gla_colour col1, gla_colour col2);
243
244    void SkinPassage(vector<XSect> & centreline, bool draw = true);
245
246    virtual void GenerateList(unsigned int l);
247    void GenerateDisplayList();
248    void GenerateDisplayListTubes();
249    void GenerateDisplayListSurface();
250    void GenerateDisplayListShadow();
251    void GenerateBlobsDisplayList();
252
253    void DrawIndicators();
254
255    void TryToFreeArrays();
256    void FirstShow();
257
258    void DrawScaleBar();
259    void DrawColourKey(int num_bands, const wxString & other, const wxString & units);
260    void DrawDepthKey();
261    void DrawDateKey();
262    void DrawErrorKey();
263    void DrawCompass();
264    void DrawClino();
265    void DrawClinoBack();
266    void Draw2dIndicators();
267    void DrawGrid();
268
269    void NattyDrawNames();
270    void SimpleDrawNames();
271
272    void DefaultParameters();
273
274    void Repaint();
275
276    void CreateHitTestGrid();
277
278    int GetCompassXPosition() const;
279    int GetClinoXPosition() const;
280    int GetIndicatorYPosition() const;
281    int GetIndicatorRadius() const;
282
283    void ToggleFlag(bool* flag, int update = UPDATE_NONE);
284
285    const GLAPen& GetPen(int band) const {
286        assert(band >= 0 && band < NUM_COLOUR_BANDS);
287        return m_Pens[band];
288    }
289
290    const GLAPen& GetSurfacePen() const { return m_Pens[NUM_COLOUR_BANDS]; }
291
292    int GetNumColourBands() const { return NUM_COLOUR_BANDS; }
293
294    void DrawShadowedBoundingBox();
295    void DrawBoundingBox();
296
297public:
298    GfxCore(MainFrm* parent, wxWindow* parent_window, GUIControl* control);
299    ~GfxCore();
300
301    void Initialise(bool same_file);
302    void InitialiseTerrain();
303
304    void UpdateBlobs();
305    void ForceRefresh();
306
307    void RefreshLine(const Point* a, const Point* b, const Point* c);
308
309    void SetHereFromTree(const LabelInfo * p);
310
311    void SetHere();
312    void SetHere(const LabelInfo * p);
313    void SetThere();
314    void SetThere(const LabelInfo * p);
315
316    void CentreOn(const Point &p);
317
318    void TranslateCave(int dx, int dy);
319    void TiltCave(Double tilt_angle);
320    void TurnCave(Double angle);
321    void TurnCaveTo(Double angle);
322
323    void OnPaint(wxPaintEvent&);
324    void OnSize(wxSizeEvent& event);
325    void OnIdle(wxIdleEvent& event);
326
327    void OnMouseMove(wxMouseEvent& event) { m_Control->OnMouseMove(event); }
328    void OnLeaveWindow(wxMouseEvent& event);
329
330    void OnLButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnLButtonDown(event); }
331    void OnLButtonUp(wxMouseEvent& event) { m_Control->OnLButtonUp(event); }
332    void OnMButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnMButtonDown(event); }
333    void OnMButtonUp(wxMouseEvent& event) { m_Control->OnMButtonUp(event); }
334    void OnRButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnRButtonDown(event); }
335    void OnRButtonUp(wxMouseEvent& event) { m_Control->OnRButtonUp(event); }
336    void OnMouseWheel(wxMouseEvent& event) { SetFocus(); m_Control->OnMouseWheel(event); }
337    void OnKeyPress(wxKeyEvent &event) { m_Control->OnKeyPress(event); }
338
339    void Animate();
340    bool Animating() const {
341        return m_Rotating || m_SwitchingTo || presentation_mode != 0;
342    }
343
344    void ClearCoords();
345    void SetCoords(wxPoint);
346
347    // Determine whether the compass is currently shown.
348    bool ShowingCompass() const { return m_Compass; }
349    // Determine whether the clino is currently shown.
350    bool ShowingClino() const { return m_Clino; }
351
352    bool PointWithinCompass(wxPoint point) const;
353    bool PointWithinClino(wxPoint point) const;
354    bool PointWithinScaleBar(wxPoint point) const;
355    bool PointWithinColourKey(wxPoint point) const;
356
357    void SetCompassFromPoint(wxPoint point);
358    void SetClinoFromPoint(wxPoint point);
359    void SetScaleBarFromOffset(wxCoord dx);
360
361    void RedrawIndicators();
362
363    void StartRotation();
364    void ToggleRotation();
365    void StopRotation();
366    bool IsExtendedElevation() const;
367    void ReverseRotation();
368    void RotateSlower(bool accel);
369    void RotateFaster(bool accel);
370
371    void SwitchToElevation();
372    void SwitchToPlan();
373
374    void SetViewTo(Double xmin, Double xmax, Double ymin, Double ymax, Double zmin, Double zmax);
375
376    double GetCompassValue() const { return m_PanAngle; }
377    bool ShowingPlan() const;
378    bool ShowingElevation() const;
379    bool ShowingMeasuringLine() const;
380    bool HereIsReal() const { return m_here && m_here != &temp_here; }
381
382    bool CanRaiseViewpoint() const;
383    bool CanLowerViewpoint() const;
384
385    bool IsRotating() const { return m_Rotating; }
386    bool HasData() const { return m_DoneFirstShow && m_HaveData; }
387    bool HasDepth() const;
388    bool HasErrorInformation() const;
389    bool HasDateInformation() const;
390
391    double GetScale() const { return m_Scale; }
392    void SetScale(Double scale);
393
394    bool ShowingStationNames() const { return m_Names; }
395    bool ShowingOverlappingNames() const { return m_OverlappingNames; }
396    bool ShowingCrosses() const { return m_Crosses; }
397    bool ShowingGrid() const { return m_Grid; }
398
399    int ColouringBy() const { return m_ColourBy; }
400
401    bool HasUndergroundLegs() const;
402    bool HasSplays() const;
403    bool HasSurfaceLegs() const;
404    bool HasTubes() const;
405
406    bool ShowingUndergroundLegs() const { return m_Legs; }
407    int ShowingSplaysMode() const { return m_Splays; }
408    bool ShowingSurfaceLegs() const { return m_Surface; }
409
410    bool ShowingColourKey() const { return m_ColourKey; }
411    bool ShowingScaleBar() const { return m_Scalebar; }
412
413    bool ShowingEntrances() const { return m_Entrances; }
414    bool ShowingFixedPts() const { return m_FixedPts; }
415    bool ShowingExportedPts() const { return m_ExportedPts; }
416
417    int GetNumEntrances() const;
418    int GetNumFixedPts() const;
419    int GetNumExportedPts() const;
420
421    void ToggleUndergroundLegs() {
422        ToggleFlag(&m_Legs, UPDATE_BLOBS_AND_CROSSES);
423    }
424    void SetSplaysMode(int mode) {
425        m_Splays = mode;
426        UpdateBlobs();
427        InvalidateList(LIST_UNDERGROUND_LEGS);
428        ForceRefresh();
429    }
430    void ToggleSurfaceLegs() {
431        ToggleFlag(&m_Surface, UPDATE_BLOBS_AND_CROSSES);
432    }
433    void ToggleCompass() {
434        ToggleFlag(&m_Compass);
435        InvalidateList(LIST_SCALE_BAR);
436    }
437    void ToggleClino() {
438        ToggleFlag(&m_Clino);
439        InvalidateList(LIST_SCALE_BAR);
440    }
441    void ToggleScaleBar() { ToggleFlag(&m_Scalebar); }
442    void ToggleEntrances() { ToggleFlag(&m_Entrances, UPDATE_BLOBS); }
443    void ToggleFixedPts() { ToggleFlag(&m_FixedPts, UPDATE_BLOBS); }
444    void ToggleExportedPts() { ToggleFlag(&m_ExportedPts, UPDATE_BLOBS); }
445    void ToggleGrid() { ToggleFlag(&m_Grid); }
446    void ToggleCrosses() { ToggleFlag(&m_Crosses); }
447    void ToggleStationNames() { ToggleFlag(&m_Names); }
448    void ToggleOverlappingNames() { ToggleFlag(&m_OverlappingNames); }
449    void ToggleColourKey() { ToggleFlag(&m_ColourKey); }
450    void ToggleMetric() {
451        ToggleFlag(&m_Metric);
452        InvalidateList(LIST_DEPTH_KEY);
453        InvalidateList(LIST_SCALE_BAR);
454    }
455    void ToggleHitTestDebug() {
456        ToggleFlag(&m_HitTestDebug);
457    }
458    void ToggleDegrees() { ToggleFlag(&m_Degrees); }
459    void TogglePercent() { ToggleFlag(&m_Percent); }
460    void ToggleTubes() { ToggleFlag(&m_Tubes); }
461    void TogglePerspective() { GLACanvas::TogglePerspective(); ForceRefresh(); }
462    void ToggleSmoothShading();
463    bool DisplayingBoundingBox() const { return m_BoundingBox; }
464    void ToggleBoundingBox() { ToggleFlag(&m_BoundingBox); }
465    void ToggleFatFinger();
466
467    bool GetMetric() const { return m_Metric; }
468    bool GetDegrees() const { return m_Degrees; }
469    bool GetPercent() const { return m_Percent; }
470    bool GetTubes() const { return m_Tubes; }
471
472    bool CheckHitTestGrid(const wxPoint& point, bool centre);
473
474    void ClearTreeSelection();
475
476    void Defaults();
477
478    void FullScreenMode();
479
480    bool IsFullScreen() const;
481
482    bool FullScreenModeShowingMenus() const;
483
484    void FullScreenModeShowMenus(bool show);
485
486    void DragFinished();
487
488    void SplitLineAcrossBands(int band, int band2,
489                              const Vector3 &p, const Vector3 &q,
490                              Double factor = 1.0);
491    int GetDepthColour(Double z) const;
492    Double GetDepthBoundaryBetweenBands(int a, int b) const;
493    void AddPolyline(const traverse & centreline);
494    void AddPolylineDepth(const traverse & centreline);
495    void AddPolylineDate(const traverse & centreline);
496    void AddPolylineError(const traverse & centreline);
497    void AddQuadrilateral(const Vector3 &a, const Vector3 &b,
498                          const Vector3 &c, const Vector3 &d);
499    void AddPolylineShadow(const traverse & centreline);
500    void AddQuadrilateralDepth(const Vector3 &a, const Vector3 &b,
501                               const Vector3 &c, const Vector3 &d);
502    void AddQuadrilateralDate(const Vector3 &a, const Vector3 &b,
503                              const Vector3 &c, const Vector3 &d);
504    void AddQuadrilateralError(const Vector3 &a, const Vector3 &b,
505                               const Vector3 &c, const Vector3 &d);
506    void MoveViewer(double forward, double up, double right);
507
508    void (GfxCore::* AddQuad)(const Vector3 &a, const Vector3 &b,
509                              const Vector3 &c, const Vector3 &d);
510    void (GfxCore::* AddPoly)(const traverse & centreline);
511
512    PresentationMark GetView() const;
513    void SetView(const PresentationMark & p);
514    void PlayPres(double speed, bool change_speed = true);
515    int GetPresentationMode() const { return presentation_mode; }
516    double GetPresentationSpeed() const { return presentation_mode ? pres_speed : 0; }
517
518    void SetColourBy(int colour_by);
519    bool ExportMovie(const wxString & fnm);
520    void OnPrint(const wxString &filename, const wxString &title,
521                 const wxString &datestamp, time_t datestamp_numeric,
522                 const wxString &cs_proj,
523                 bool close_after_print = false);
524    void OnExport(const wxString &filename, const wxString &title,
525                  const wxString &datestamp, time_t datestamp_numeric,
526                  const wxString &cs_proj);
527    void UpdateCursor(GfxCore::cursor new_cursor);
528    bool MeasuringLineActive() const;
529
530    bool HandleRClick(wxPoint point);
531
532    void InvalidateAllLists() {
533        for (int i = 0; i < LIST_LIMIT_; ++i) {
534            InvalidateList(i);
535        }
536    }
537
538    void SetZoomBox(wxPoint p1, wxPoint p2, bool centred, bool aspect);
539
540    void UnsetZoomBox() {
541        if (!zoombox.active()) return;
542        zoombox.unset();
543        ForceRefresh();
544    }
545
546    void ZoomBoxGo();
547
548private:
549    DECLARE_EVENT_TABLE()
550};
551
552#endif
Note: See TracBrowser for help on using the repository browser.