canvas.hh
Go to the documentation of this file.
1
2#include "option.hh"
3#include "stage.hh"
4
5#include <map>
6#include <stack>
7
8namespace Stg {
9class Canvas : public Fl_Gl_Window {
10 friend class WorldGui; // allow access to private members
11 friend class Model;
12
13private:
14 class GlColorStack {
15 public:
16 GlColorStack() : colorstack() {}
17 ~GlColorStack() {}
18 void Push(double r, double g, double b, double a = 1.0) { Push(Color(r, g, b, a)); }
19 void Push(Color col)
20 {
21 colorstack.push(col);
22 glColor4f(col.r, col.g, col.b, col.a);
23 }
24
25 void Pop()
26 {
27 if (colorstack.size() < 1)
28 PRINT_WARN1("Attempted to ColorStack.Pop() but ColorStack %p is empty",
29 static_cast<void *>(this));
30 else {
31 Color &old = colorstack.top();
32 colorstack.pop();
33 glColor4f(old.r, old.g, old.b, old.a);
34 }
35 }
36
37 unsigned int Length() { return colorstack.size(); }
38 private:
39 std::stack<Color> colorstack;
40 } colorstack;
41
42 std::list<Model *> models_sorted;
43
44 Camera *current_camera;
45 OrthoCamera camera;
46 PerspectiveCamera perspective_camera;
47 bool dirty_buffer;
48 Worldfile *wf;
49
50 int startx, starty;
51 bool selectedModel;
52 bool clicked_empty_space;
53 int empty_space_startx, empty_space_starty;
54 std::list<Model *> selected_models;
55 Model *last_selection;
57
58 msec_t interval; // window refresh interval in ms
59
60 void RecordRay(double x1, double y1, double x2, double y2);
61 void DrawRays();
62 void ClearRays();
63 void DrawGlobalGrid();
64
65 void AddModel(Model *mod);
66 void RemoveModel(Model *mod);
67
68 Option // showBlinken,
69 showBBoxes,
70 showBlocks, showBlur, showClock, showData, showFlags, showFollow, showFootprints, showGrid,
71 showOccupancy, showScreenshots, showStatus, showTrailArrows, showTrailRise, showTrails,
72 showVoxels, pCamOn, visualizeAll;
73
74public:
75 Canvas(WorldGui *world, int x, int y, int width, int height);
76 ~Canvas();
77
80 unsigned long frames_rendered_count;
82
83 std::map<std::string, Option *> _custom_options;
84
85 void Screenshot();
86 void InitGl();
87 void InitTextures();
88 void createMenuItems(Fl_Menu_Bar *menu, std::string path);
89
90 void FixViewport(int W, int H);
91 void DrawFloor(); // simpler floor compared to grid
92 void DrawBlocks();
93 void DrawBoundingBoxes();
94 void resetCamera();
95 virtual void renderFrame();
96 virtual void draw();
97 virtual int handle(int event);
98 void resize(int X, int Y, int W, int H);
99
100 void CanvasToWorld(int px, int py, double *wx, double *wy, double *wz);
101
102 Model *getModel(int x, int y);
103 bool selected(Model *mod);
104 void select(Model *mod);
105 void unSelect(Model *mod);
106 void unSelectAll();
107
108 inline void setDirtyBuffer(void) { dirty_buffer = true; }
109 inline bool dirtyBuffer(void) const { return dirty_buffer; }
110 void PushColor(Color col) { colorstack.Push(col); }
111 void PushColor(double r, double g, double b, double a) { colorstack.Push(r, g, b, a); }
112 void PopColor() { colorstack.Pop(); }
113 void InvertView(uint32_t invertflags);
114
115 bool VisualizeAll() { return !visualizeAll; }
116 static void TimerCallback(Canvas *canvas);
117 static void perspectiveCb(Fl_Widget *w, void *p);
118
119 void EnterScreenCS();
120 void LeaveScreenCS();
121
122 void Load(Worldfile *wf, int section);
123 void Save(Worldfile *wf, int section);
124
125 bool IsTopView() { return ((fabs(camera.yaw()) < 0.1) && (fabs(camera.pitch()) < 0.1)); }
126};
127
128} // namespace Stg
Definition: canvas.hh:9
void InitGl()
Definition: canvas.cc:96
unsigned long frames_rendered_count
Definition: canvas.hh:80
void DrawBoundingBoxes()
Definition: canvas.cc:691
static void perspectiveCb(Fl_Widget *w, void *p)
Definition: canvas.cc:1116
void PushColor(double r, double g, double b, double a)
Definition: canvas.hh:111
void CanvasToWorld(int px, int py, double *wx, double *wy, double *wz)
Definition: canvas.cc:306
void resize(int X, int Y, int W, int H)
Definition: canvas.cc:1254
~Canvas()
Definition: canvas.cc:198
void select(Model *mod)
Definition: canvas.cc:281
friend class Model
Definition: canvas.hh:11
static void TimerCallback(Canvas *canvas)
Definition: canvas.cc:42
void setDirtyBuffer(void)
Definition: canvas.hh:108
virtual void draw()
Definition: canvas.cc:1214
void DrawBlocks()
Definition: canvas.cc:685
virtual int handle(int event)
Definition: canvas.cc:345
bool dirtyBuffer(void) const
Definition: canvas.hh:109
void LeaveScreenCS()
Definition: canvas.cc:1050
void unSelectAll()
Definition: canvas.cc:300
Model * getModel(int x, int y)
Definition: canvas.cc:203
WorldGui * world
Definition: canvas.hh:79
std::map< std::string, Option * > _custom_options
Definition: canvas.hh:83
void unSelect(Model *mod)
Definition: canvas.cc:292
void EnterScreenCS()
Definition: canvas.cc:1036
void InitTextures()
Definition: canvas.cc:129
void FixViewport(int W, int H)
Definition: canvas.cc:577
Canvas(WorldGui *world, int x, int y, int width, int height)
Definition: canvas.cc:53
void DrawFloor()
Definition: canvas.cc:668
void createMenuItems(Fl_Menu_Bar *menu, std::string path)
Definition: canvas.cc:1130
bool selected(Model *mod)
Definition: canvas.cc:276
int screenshot_frame_skip
Definition: canvas.hh:81
virtual void renderFrame()
Definition: canvas.cc:756
friend class WorldGui
Definition: canvas.hh:10
void InvertView(uint32_t invertflags)
void PushColor(Color col)
Definition: canvas.hh:110
void resetCamera()
Definition: canvas.cc:705
void Screenshot()
Definition: canvas.cc:1059
void PopColor()
Definition: canvas.hh:112
bool graphics
Definition: canvas.hh:78
void Save(Worldfile *wf, int section)
Definition: canvas.cc:1189
bool IsTopView()
Definition: canvas.hh:125
bool VisualizeAll()
Definition: canvas.hh:115
void Load(Worldfile *wf, int section)
Definition: canvas.cc:1153
Definition: stage.hh:214
Model class
Definition: stage.hh:1651
Definition: stage.hh:1421
Definition: worldfile.hh:67
The Stage library uses its own namespace.
Definition: canvas.hh:8
unsigned long msec_t
Definition: stage.hh:200
#define PRINT_WARN1(m, a)
Definition: stage.hh:604