canvas.hh
Go to the documentation of this file.
1 
2 #include "stage.hh"
3 #include "option.hh"
4 
5 #include <map>
6 #include <stack>
7 
8 namespace Stg
9 {
10  class Canvas : public Fl_Gl_Window
11  {
12  friend class WorldGui; // allow access to private members
13  friend class Model;
14 
15  private:
16 
17  class GlColorStack
18  {
19  public:
20  GlColorStack() : colorstack() {}
21  ~GlColorStack() {}
22 
23  void Push( double r, double g, double b, double a=1.0 )
24  {
25  Push( Color(r,g,b,a) );
26  }
27 
28  void Push( Color col )
29  {
30  colorstack.push( col );
31  glColor4f( col.r, col.g, col.b, col.a );
32  }
33 
34  void Pop()
35  {
36  if( colorstack.size() < 1 )
37  PRINT_WARN1( "Attempted to ColorStack.Pop() but ColorStack %p is empty",
38  this );
39  else
40  {
41  Color& old = colorstack.top();
42  colorstack.pop();
43  glColor4f( old.r, old.g, old.b, old.a );
44  }
45  }
46 
47  unsigned int Length()
48  { return colorstack.size(); }
49 
50  private:
51  std::stack<Color> colorstack;
52  } colorstack;
53 
54  std::list<Model*> models_sorted;
55 
56  Camera* current_camera;
57  OrthoCamera camera;
58  PerspectiveCamera perspective_camera;
59  bool dirty_buffer;
60  Worldfile* wf;
61 
62  int startx, starty;
63  bool selectedModel;
64  bool clicked_empty_space;
65  int empty_space_startx, empty_space_starty;
66  std::list<Model*> selected_models;
67  Model* last_selection;
68 
70  msec_t interval; // window refresh interval in ms
71 
72  void RecordRay( double x1, double y1, double x2, double y2 );
73  void DrawRays();
74  void ClearRays();
75  void DrawGlobalGrid();
76 
77  void AddModel( Model* mod );
78  void RemoveModel( Model* mod );
79 
80  Option //showBlinken,
81  showBBoxes,
82  showBlocks,
83  showBlur,
84  showClock,
85  showData,
86  showFlags,
87  showFollow,
88  showFootprints,
89  showGrid,
90  showOccupancy,
91  showScreenshots,
92  showStatus,
93  showTrailArrows,
94  showTrailRise,
95  showTrails,
96  showVoxels,
97  pCamOn,
98  visualizeAll;
99 
100  public:
101  Canvas( WorldGui* world, int x, int y, int width, int height);
102  ~Canvas();
103 
104  bool graphics;
106  unsigned long frames_rendered_count;
108 
109  std::map< std::string, Option* > _custom_options;
110 
111  void Screenshot();
112  void InitGl();
113  void InitTextures();
114  void createMenuItems( Fl_Menu_Bar* menu, std::string path );
115 
116  void FixViewport(int W,int H);
117  void DrawFloor(); //simpler floor compared to grid
118  void DrawBlocks();
119  void DrawBoundingBoxes();
120  void resetCamera();
121  virtual void renderFrame();
122  virtual void draw();
123  virtual int handle( int event );
124  void resize(int X,int Y,int W,int H);
125 
126  void CanvasToWorld( int px, int py,
127  double *wx, double *wy, double* wz );
128 
129  Model* getModel( int x, int y );
130  bool selected( Model* mod );
131  void select( Model* mod );
132  void unSelect( Model* mod );
133  void unSelectAll();
134 
135  inline void setDirtyBuffer( void ) { dirty_buffer = true; }
136  inline bool dirtyBuffer( void ) const { return dirty_buffer; }
137 
138  void PushColor( Color col )
139  { colorstack.Push( col ); }
140 
141  void PushColor( double r, double g, double b, double a )
142  { colorstack.Push( r,g,b,a ); }
143 
144  void PopColor(){ colorstack.Pop(); }
145 
146  void InvertView( uint32_t invertflags );
147 
148  bool VisualizeAll(){ return ! visualizeAll; }
149 
150  static void TimerCallback( Canvas* canvas );
151  static void perspectiveCb( Fl_Widget* w, void* p );
152 
153  void EnterScreenCS();
154  void LeaveScreenCS();
155 
156  void Load( Worldfile* wf, int section );
157  void Save( Worldfile* wf, int section );
158 
159  bool IsTopView(){ return( (fabs( camera.yaw() ) < 0.1) &&
160  (fabs( camera.pitch() ) < 0.1) ); }
161  };
162 
163 } // namespace Stg
Model class
Definition: stage.hh:1742
WorldGui * world
Definition: canvas.hh:105
The Stage library uses its own namespace.
Definition: canvas.hh:8
~Canvas()
Definition: canvas.cc:218
void InitTextures()
Definition: canvas.cc:144
void select(Model *mod)
Definition: canvas.cc:301
void EnterScreenCS()
Definition: canvas.cc:1087
void setDirtyBuffer(void)
Definition: canvas.hh:135
void DrawFloor()
Definition: canvas.cc:697
virtual int handle(int event)
Definition: canvas.cc:364
void createMenuItems(Fl_Menu_Bar *menu, std::string path)
Definition: canvas.cc:1188
friend class Model
Definition: canvas.hh:13
void DrawBoundingBoxes()
Definition: canvas.cc:720
Canvas(WorldGui *world, int x, int y, int width, int height)
Definition: canvas.cc:56
void DrawBlocks()
Definition: canvas.cc:714
bool graphics
Definition: canvas.hh:104
void resetCamera()
Definition: canvas.cc:734
void PushColor(Color col)
Definition: canvas.hh:138
std::map< std::string, Option *> _custom_options
Definition: canvas.hh:109
void Screenshot()
Definition: canvas.cc:1111
void FixViewport(int W, int H)
Definition: canvas.cc:600
int screenshot_frame_skip
Definition: canvas.hh:107
void CanvasToWorld(int px, int py, double *wx, double *wy, double *wz)
Definition: canvas.cc:327
friend class WorldGui
Definition: canvas.hh:12
void unSelectAll()
Definition: canvas.cc:321
Definition: stage.hh:1498
virtual void draw()
Definition: canvas.cc:1276
void LeaveScreenCS()
Definition: canvas.cc:1101
unsigned long msec_t
Definition: stage.hh:183
Definition: stage.hh:197
Model * getModel(int x, int y)
Definition: canvas.cc:223
void PopColor()
Definition: canvas.hh:144
static void perspectiveCb(Fl_Widget *w, void *p)
Definition: canvas.cc:1173
void Save(Worldfile *wf, int section)
Definition: canvas.cc:1250
void PushColor(double r, double g, double b, double a)
Definition: canvas.hh:141
void Load(Worldfile *wf, int section)
Definition: canvas.cc:1212
bool dirtyBuffer(void) const
Definition: canvas.hh:136
Definition: worldfile.hh:69
void InitGl()
Definition: canvas.cc:111
unsigned long frames_rendered_count
Definition: canvas.hh:106
Definition: canvas.hh:10
bool VisualizeAll()
Definition: canvas.hh:148
bool selected(Model *mod)
Definition: canvas.cc:296
void resize(int X, int Y, int W, int H)
Definition: canvas.cc:1324
virtual void renderFrame()
Definition: canvas.cc:787
#define PRINT_WARN1(m, a)
Definition: stage.hh:634
bool IsTopView()
Definition: canvas.hh:159
static void TimerCallback(Canvas *canvas)
Definition: canvas.cc:42
void InvertView(uint32_t invertflags)
void unSelect(Model *mod)
Definition: canvas.cc:312