source: git/src/gfxcore.h @ 793b6a3

line_contentsstereotravis-osx
Last change on this file since 793b6a3 was 793b6a3, checked in by Olly Betts <olly@…>, 5 years ago

src/gfxcore.h: Fix (C) year typo.

  • Property mode set to 100644
File size: 15.5 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,2015 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
109// It's pointless to redraw the screen as often as we can on a fast machine,
110// since the display hardware will only update so many times per second.
111// This is the maximum framerate we'll redraw at.
112const int MAX_FRAMERATE = 50;
113
114class GfxCore : public GLACanvas {
115    Double m_Scale;
116    int m_ScaleBarWidth;
117
118    typedef enum {
119        LIST_COMPASS,
120        LIST_CLINO,
121        LIST_CLINO_BACK,
122        LIST_SCALE_BAR,
123        LIST_DEPTH_KEY,
124        LIST_DATE_KEY,
125        LIST_ERROR_KEY,
126        LIST_UNDERGROUND_LEGS,
127        LIST_TUBES,
128        LIST_SURFACE_LEGS,
129        LIST_BLOBS,
130        LIST_CROSSES,
131        LIST_GRID,
132        LIST_SHADOW,
133        LIST_LIMIT_ // Leave this last.
134    } drawing_list;
135
136    static const int NUM_COLOUR_BANDS = 13;
137
138    void SetPanBase() {
139        base_pan = m_PanAngle;
140        base_pan_time = timer.Time() - (1000 / MAX_FRAMERATE);
141    }
142
143    void SetTiltBase() {
144        base_tilt = m_TiltAngle;
145        base_tilt_time = timer.Time() - (1000 / MAX_FRAMERATE);
146    }
147
148public:
149    typedef enum {
150        CURSOR_DEFAULT,
151        CURSOR_POINTING_HAND,
152        CURSOR_DRAGGING_HAND,
153        CURSOR_HORIZONTAL_RESIZE,
154        CURSOR_ROTATE_HORIZONTALLY,
155        CURSOR_ROTATE_VERTICALLY,
156        CURSOR_ROTATE_EITHER_WAY,
157        CURSOR_ZOOM,
158        CURSOR_ZOOM_ROTATE
159    } cursor;
160
161private:
162    GUIControl* m_Control;
163    char* m_LabelGrid;
164    MainFrm* m_Parent;
165    bool m_DoneFirstShow;
166    Double m_TiltAngle;
167    Double m_PanAngle;
168    bool m_Rotating;
169    Double m_RotationStep;
170    int m_SwitchingTo;
171    bool m_Crosses;
172    bool m_Legs;
173    int m_Splays;
174    bool m_Names;
175    bool m_Scalebar;
176    bool m_ColourKey;
177    bool m_OverlappingNames;
178    bool m_Compass;
179    bool m_Clino;
180    bool m_Tubes;
181    int m_ColourBy;
182
183    bool m_HaveData;
184    bool m_MouseOutsideCompass;
185    bool m_MouseOutsideElev;
186    bool m_Surface;
187    bool m_Entrances;
188    bool m_FixedPts;
189    bool m_ExportedPts;
190    bool m_Grid;
191    bool m_BoundingBox;
192
193    bool m_Degrees;
194    bool m_Metric;
195    bool m_Percent;
196
197    bool m_HitTestDebug;
198
199    list<LabelInfo*> *m_PointGrid;
200    bool m_HitTestGridValid;
201
202    LabelInfo temp_here;
203    const LabelInfo * m_here;
204    const LabelInfo * m_there;
205
206    wxStopWatch timer;
207    long base_tilt_time;
208    long base_pan_time;
209    Double base_tilt;
210    Double base_pan;
211
212    GLAPen m_Pens[NUM_COLOUR_BANDS + 1];
213
214#define PLAYING 1
215    int presentation_mode; // for now, 0 => off, PLAYING => continuous play
216    bool pres_reverse;
217    double pres_speed;
218    PresentationMark next_mark;
219    double next_mark_time;
220    double this_mark_total;
221
222    MovieMaker * movie;
223
224    cursor current_cursor;
225
226    int sqrd_measure_threshold;
227
228    // The legends for each entry in the colour key.
229    wxString key_legends[NUM_COLOUR_BANDS];
230
231    wxPoint key_lowerleft[COLOUR_BY_LIMIT_];
232
233    ZoomBox zoombox;
234
235    void PlaceVertexWithColour(const Vector3 &v, Double factor = 1.0);
236    void PlaceVertexWithColour(const Vector3 & v, GLint tex_x, GLint tex_y,
237                               Double factor);
238    void SetDepthColour(Double z, Double factor);
239    void PlaceVertexWithDepthColour(const Vector3 & v, Double factor = 1.0);
240    void PlaceVertexWithDepthColour(const Vector3 & v, GLint tex_x, GLint tex_y, Double factor);
241
242    void SetColourFromDate(int date, Double factor);
243    void SetColourFromError(double E, Double factor);
244
245    int GetClinoOffset() const;
246    void DrawTick(int angle_cw);
247    void DrawArrow(gla_colour col1, gla_colour col2);
248
249    void SkinPassage(vector<XSect> & centreline, bool draw = true);
250
251    virtual void GenerateList(unsigned int l);
252    void GenerateDisplayList();
253    void GenerateDisplayListTubes();
254    void GenerateDisplayListSurface();
255    void GenerateDisplayListShadow();
256    void GenerateBlobsDisplayList();
257
258    void DrawIndicators();
259
260    void TryToFreeArrays();
261    void FirstShow();
262
263    void DrawScaleBar();
264    void DrawColourKey(int num_bands, const wxString & other, const wxString & units);
265    void DrawDepthKey();
266    void DrawDateKey();
267    void DrawErrorKey();
268    void DrawCompass();
269    void DrawClino();
270    void DrawClinoBack();
271    void Draw2dIndicators();
272    void DrawGrid();
273
274    void NattyDrawNames();
275    void SimpleDrawNames();
276
277    void DefaultParameters();
278
279    void Repaint();
280
281    void CreateHitTestGrid();
282
283    int GetCompassXPosition() const;
284    int GetClinoXPosition() const;
285    int GetIndicatorYPosition() const;
286    int GetIndicatorRadius() const;
287
288    void ToggleFlag(bool* flag, int update = UPDATE_NONE);
289
290    const GLAPen& GetPen(int band) const {
291        assert(band >= 0 && band < NUM_COLOUR_BANDS);
292        return m_Pens[band];
293    }
294
295    const GLAPen& GetSurfacePen() const { return m_Pens[NUM_COLOUR_BANDS]; }
296
297    int GetNumColourBands() const { return NUM_COLOUR_BANDS; }
298
299    void DrawShadowedBoundingBox();
300    void DrawBoundingBox();
301
302public:
303    GfxCore(MainFrm* parent, wxWindow* parent_window, GUIControl* control);
304    ~GfxCore();
305
306    void Initialise(bool same_file);
307    void InitialiseTerrain();
308
309    void UpdateBlobs();
310    void ForceRefresh();
311
312    void RefreshLine(const Point* a, const Point* b, const Point* c);
313
314    void SetHereFromTree(const LabelInfo * p);
315
316    void SetHere();
317    void SetHere(const LabelInfo * p);
318    void SetThere();
319    void SetThere(const LabelInfo * p);
320
321    void CentreOn(const Point &p);
322
323    void TranslateCave(int dx, int dy);
324    void TiltCave(Double tilt_angle);
325    void TurnCave(Double angle);
326    void TurnCaveTo(Double angle);
327
328    void OnPaint(wxPaintEvent&);
329    void OnSize(wxSizeEvent& event);
330    void OnIdle(wxIdleEvent& event);
331
332    void OnMouseMove(wxMouseEvent& event) { m_Control->OnMouseMove(event); }
333    void OnLeaveWindow(wxMouseEvent& event);
334
335    void OnLButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnLButtonDown(event); }
336    void OnLButtonUp(wxMouseEvent& event) { m_Control->OnLButtonUp(event); }
337    void OnMButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnMButtonDown(event); }
338    void OnMButtonUp(wxMouseEvent& event) { m_Control->OnMButtonUp(event); }
339    void OnRButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnRButtonDown(event); }
340    void OnRButtonUp(wxMouseEvent& event) { m_Control->OnRButtonUp(event); }
341    void OnMouseWheel(wxMouseEvent& event) { SetFocus(); m_Control->OnMouseWheel(event); }
342    void OnKeyPress(wxKeyEvent &event) { m_Control->OnKeyPress(event); }
343
344    void Animate();
345    bool Animating() const {
346        return m_Rotating || m_SwitchingTo || presentation_mode != 0;
347    }
348
349    void ClearCoords();
350    void SetCoords(wxPoint);
351
352    // Determine whether the compass is currently shown.
353    bool ShowingCompass() const { return m_Compass; }
354    // Determine whether the clino is currently shown.
355    bool ShowingClino() const { return m_Clino; }
356
357    bool PointWithinCompass(wxPoint point) const;
358    bool PointWithinClino(wxPoint point) const;
359    bool PointWithinScaleBar(wxPoint point) const;
360    bool PointWithinColourKey(wxPoint point) const;
361
362    void SetCompassFromPoint(wxPoint point);
363    void SetClinoFromPoint(wxPoint point);
364    void SetScaleBarFromOffset(wxCoord dx);
365
366    void RedrawIndicators();
367
368    void StartRotation();
369    void ToggleRotation();
370    void StopRotation();
371    bool IsExtendedElevation() const;
372    void ReverseRotation();
373    void RotateSlower(bool accel);
374    void RotateFaster(bool accel);
375
376    void SwitchToElevation();
377    void SwitchToPlan();
378
379    void SetViewTo(Double xmin, Double xmax, Double ymin, Double ymax, Double zmin, Double zmax);
380
381    double GetCompassValue() const { return m_PanAngle; }
382    bool ShowingPlan() const;
383    bool ShowingElevation() const;
384    bool ShowingMeasuringLine() const;
385    bool HereIsReal() const { return m_here && m_here != &temp_here; }
386
387    bool CanRaiseViewpoint() const;
388    bool CanLowerViewpoint() const;
389
390    bool IsRotating() const { return m_Rotating; }
391    bool HasData() const { return m_DoneFirstShow && m_HaveData; }
392    bool HasDepth() const;
393    bool HasErrorInformation() const;
394    bool HasDateInformation() const;
395
396    double GetScale() const { return m_Scale; }
397    void SetScale(Double scale);
398
399    bool ShowingStationNames() const { return m_Names; }
400    bool ShowingOverlappingNames() const { return m_OverlappingNames; }
401    bool ShowingCrosses() const { return m_Crosses; }
402    bool ShowingGrid() const { return m_Grid; }
403
404    int ColouringBy() const { return m_ColourBy; }
405
406    bool HasUndergroundLegs() const;
407    bool HasSplays() const;
408    bool HasSurfaceLegs() const;
409    bool HasTubes() const;
410
411    bool ShowingUndergroundLegs() const { return m_Legs; }
412    int ShowingSplaysMode() const { return m_Splays; }
413    bool ShowingSurfaceLegs() const { return m_Surface; }
414
415    bool ShowingColourKey() const { return m_ColourKey; }
416    bool ShowingScaleBar() const { return m_Scalebar; }
417
418    bool ShowingEntrances() const { return m_Entrances; }
419    bool ShowingFixedPts() const { return m_FixedPts; }
420    bool ShowingExportedPts() const { return m_ExportedPts; }
421
422    int GetNumEntrances() const;
423    int GetNumFixedPts() const;
424    int GetNumExportedPts() const;
425
426    void ToggleUndergroundLegs() {
427        ToggleFlag(&m_Legs, UPDATE_BLOBS_AND_CROSSES);
428    }
429    void SetSplaysMode(int mode) {
430        m_Splays = mode;
431        UpdateBlobs();
432        InvalidateList(LIST_UNDERGROUND_LEGS);
433        ForceRefresh();
434    }
435    void ToggleSurfaceLegs() {
436        ToggleFlag(&m_Surface, UPDATE_BLOBS_AND_CROSSES);
437    }
438    void ToggleCompass() {
439        ToggleFlag(&m_Compass);
440        InvalidateList(LIST_SCALE_BAR);
441    }
442    void ToggleClino() {
443        ToggleFlag(&m_Clino);
444        InvalidateList(LIST_SCALE_BAR);
445    }
446    void ToggleScaleBar() { ToggleFlag(&m_Scalebar); }
447    void ToggleEntrances() { ToggleFlag(&m_Entrances, UPDATE_BLOBS); }
448    void ToggleFixedPts() { ToggleFlag(&m_FixedPts, UPDATE_BLOBS); }
449    void ToggleExportedPts() { ToggleFlag(&m_ExportedPts, UPDATE_BLOBS); }
450    void ToggleGrid() { ToggleFlag(&m_Grid); }
451    void ToggleCrosses() { ToggleFlag(&m_Crosses); }
452    void ToggleStationNames() { ToggleFlag(&m_Names); }
453    void ToggleOverlappingNames() { ToggleFlag(&m_OverlappingNames); }
454    void ToggleColourKey() { ToggleFlag(&m_ColourKey); }
455    void ToggleMetric() {
456        ToggleFlag(&m_Metric);
457        InvalidateList(LIST_DEPTH_KEY);
458        InvalidateList(LIST_SCALE_BAR);
459    }
460    void ToggleHitTestDebug() {
461        ToggleFlag(&m_HitTestDebug);
462    }
463    void ToggleDegrees() { ToggleFlag(&m_Degrees); }
464    void TogglePercent() { ToggleFlag(&m_Percent); }
465    void ToggleTubes() { ToggleFlag(&m_Tubes); }
466    void TogglePerspective() { GLACanvas::TogglePerspective(); ForceRefresh(); }
467    void ToggleSmoothShading();
468    bool DisplayingBoundingBox() const { return m_BoundingBox; }
469    void ToggleBoundingBox() { ToggleFlag(&m_BoundingBox); }
470    void ToggleFatFinger();
471
472    bool GetMetric() const { return m_Metric; }
473    bool GetDegrees() const { return m_Degrees; }
474    bool GetPercent() const { return m_Percent; }
475    bool GetTubes() const { return m_Tubes; }
476
477    bool CheckHitTestGrid(const wxPoint& point, bool centre);
478
479    void ClearTreeSelection();
480
481    void Defaults();
482
483    void FullScreenMode();
484
485    bool IsFullScreen() const;
486
487    bool FullScreenModeShowingMenus() const;
488
489    void FullScreenModeShowMenus(bool show);
490
491    void DragFinished();
492
493    void SplitLineAcrossBands(int band, int band2,
494                              const Vector3 &p, const Vector3 &q,
495                              Double factor = 1.0);
496    int GetDepthColour(Double z) const;
497    Double GetDepthBoundaryBetweenBands(int a, int b) const;
498    void AddPolyline(const traverse & centreline);
499    void AddPolylineDepth(const traverse & centreline);
500    void AddPolylineDate(const traverse & centreline);
501    void AddPolylineError(const traverse & centreline);
502    void AddQuadrilateral(const Vector3 &a, const Vector3 &b,
503                          const Vector3 &c, const Vector3 &d);
504    void AddPolylineShadow(const traverse & centreline);
505    void AddQuadrilateralDepth(const Vector3 &a, const Vector3 &b,
506                               const Vector3 &c, const Vector3 &d);
507    void AddQuadrilateralDate(const Vector3 &a, const Vector3 &b,
508                              const Vector3 &c, const Vector3 &d);
509    void AddQuadrilateralError(const Vector3 &a, const Vector3 &b,
510                               const Vector3 &c, const Vector3 &d);
511    void MoveViewer(double forward, double up, double right);
512
513    void (GfxCore::* AddQuad)(const Vector3 &a, const Vector3 &b,
514                              const Vector3 &c, const Vector3 &d);
515    void (GfxCore::* AddPoly)(const traverse & centreline);
516
517    PresentationMark GetView() const;
518    void SetView(const PresentationMark & p);
519    void PlayPres(double speed, bool change_speed = true);
520    int GetPresentationMode() const { return presentation_mode; }
521    double GetPresentationSpeed() const { return presentation_mode ? pres_speed : 0; }
522
523    void SetColourBy(int colour_by);
524    bool ExportMovie(const wxString & fnm);
525    void OnPrint(const wxString &filename, const wxString &title,
526                 const wxString &datestamp, time_t datestamp_numeric,
527                 const wxString &cs_proj,
528                 bool close_after_print = false);
529    void OnExport(const wxString &filename, const wxString &title,
530                  const wxString &datestamp, time_t datestamp_numeric,
531                  const wxString &cs_proj);
532    void UpdateCursor(GfxCore::cursor new_cursor);
533    bool MeasuringLineActive() const;
534
535    bool HandleRClick(wxPoint point);
536
537    void InvalidateAllLists() {
538        for (int i = 0; i < LIST_LIMIT_; ++i) {
539            InvalidateList(i);
540        }
541    }
542
543    void SetZoomBox(wxPoint p1, wxPoint p2, bool centred, bool aspect);
544
545    void UnsetZoomBox() {
546        if (!zoombox.active()) return;
547        zoombox.unset();
548        ForceRefresh();
549    }
550
551    void ZoomBoxGo();
552
553private:
554    DECLARE_EVENT_TABLE()
555};
556
557#endif
Note: See TracBrowser for help on using the repository browser.