source: git/src/gfxcore.h @ 371f9ed

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

src/gfxcore.cc,src/gfxcore.h: Factor out function to pick the colour
pen based on a value between 0 and 1.

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