1
//------------------------------------------------------------------------
2
// GRID : Draws the map (lines, nodes, etc)
3
//------------------------------------------------------------------------
5
// GL-Node Viewer (C) 2004-2007 Andrew Apted
7
// This program is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU General Public License
9
// as published by the Free Software Foundation; either version 2
10
// of the License, or (at your option) any later version.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
//------------------------------------------------------------------------
19
#ifndef __NODEVIEW_GRID_H__
20
#define __NODEVIEW_GRID_H__
22
class W_Grid : public Fl_Widget
25
W_Grid(int X, int Y, int W, int H, const char *label = 0);
28
void SetZoom(int new_zoom);
29
// changes the current zoom factor.
31
void SetPos(double new_x, double new_y);
32
// changes the current position.
34
void SetPath(path_c *p) { path = p; }
35
// give a path for the grid to draw
37
void ClearPath() { SetPath(NULL); }
39
void FitBBox(double lx, double ly, double hx, double hy);
40
// set zoom and position so that the bounding area fits.
42
void MapToWin(double mx, double my, int *X, int *Y) const;
43
// convert a map coordinate into a window coordinate, using
44
// current grid position and zoom factor.
46
void WinToMap(int X, int Y, double *mx, double *my) const;
47
// convert a map coordinate into a window coordinate, using
48
// current grid position and zoom factor.
51
int handle(int event);
52
// FLTK virtual method for handling input events.
54
void resize(int X, int Y, int W, int H);
55
// FLTK virtual method for resizing.
59
// FLTK virtual method for drawing.
61
void draw_grid(double spacing, int ity);
62
void draw_partition(const node_c *nd, int ity);
63
void draw_bbox(const bbox_t *bbox, int ity);
64
void draw_all_partitions();
66
void draw_node(const node_c *nd, int pos, bool on_route);
67
void draw_child(const child_t *ch, int pos, bool on_route);
68
void draw_subsector(const subsec_c *sub, int pos, bool on_route);
71
bool set_seg_color(seg_c *seg, bool on);
72
void draw_line(double x1, double y1, double x2, double y2);
74
void scroll(int dx, int dy);
76
void new_node_or_sub(void);
79
int handle_key(int key);
81
void handle_mouse(int wx, int wy);
85
// zoom factor: (2 ^ (zoom/2)) pixels per 512 units on the map
88
// derived from 'zoom'.
90
static const int MIN_GRID_ZOOM = 3;
91
static const int DEF_GRID_ZOOM = 18; // 1:1 ratio
92
static const int MAX_GRID_ZOOM = 30;
105
static const int MAX_ROUTE = 2000;
107
static const char RT_RIGHT = 0;
108
static const char RT_LEFT = 1;
113
bool descend_by_mouse(int wx, int wy); // true if OK
114
bool descend_tree(char side); // true if OK
116
void lowest_node(node_c **nd, subsec_c **sub, bbox_t **bbox);
118
static inline int GRID_FIND(double x, double y)
120
return int(x - fmod(x,y) + (x < 0) ? y : 0);
123
static const int O_TOP = 1;
124
static const int O_BOTTOM = 2;
125
static const int O_LEFT = 4;
126
static const int O_RIGHT = 8;
128
static int MAP_OUTCODE(double x, double y,
129
double lx, double ly, double hx, double hy)
132
((y < ly) ? O_BOTTOM : 0) |
133
((y > hy) ? O_TOP : 0) |
134
((x < lx) ? O_LEFT : 0) |
135
((x > hx) ? O_RIGHT : 0);
140
#endif /* __NODEVIEW_GRID_H__ */