-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview.h
252 lines (189 loc) · 5.04 KB
/
view.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#ifndef _FLY_INC_
#define _FLY_INC_
#include <iostream>
#include <memory>
#include <FL/gl.h>
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#define MW_OFFSET 2
//#define MW_WIDTH 640
//#define MW_HEIGHT 480
#define MW_WIDTH 980
#define MW_HEIGHT 640
#define MW_COLS 4
#define MW_ROWS 4
#define DEFAULT_STAT_HEIGHT 80
namespace vid
{
class IView;
class CamViewStub;
class CamViewTest;
class MainView;
class IFrameReceiver;
typedef std::shared_ptr<IFrameReceiver> IFrameReceiverSPtr;
struct Geometry;
class ViewPlacer; ///< @todo remove
class ViewPlacerEx;
std::ostream &operator<<(std::ostream &, const IView &);
class StatPanel;
}
struct vid::Geometry {
unsigned x, y, w, h;
};
class vid::ViewPlacer {
public:
ViewPlacer(unsigned c, unsigned r,
unsigned w, unsigned h,
unsigned left_margins, unsigned top_margins) :
cols(c), rows(r),
W(w),
width(w/c), height(h/r), current(0), max(c*r), lm(left_margins), tm(top_margins) {}
public:
unsigned x() const { return lm + (current % cols ) * width ; }
unsigned y() const { return W - tm - (current / rows + 1 ) * height ; }
unsigned w() const { return width; }
unsigned h() const { return height; }
private:
unsigned cols, rows, W, width, height, current, max, lm, tm;
};
class vid::ViewPlacerEx {
public:
ViewPlacerEx(unsigned i, unsigned j,
unsigned c, unsigned r,
unsigned W, unsigned H,
unsigned left_margins, unsigned top_margins) :
i(i), j(j),
cols(c), rows(r),
H(H),
width(W/c), height(H/r), max(c*r), lm(left_margins), tm(top_margins) {}
public:
unsigned x() const { return lm + ( pos() % cols ) * width ; }
unsigned y() const { return tm + H - ( pos() / rows + 1 ) * height ; }
unsigned w() const { return width; }
unsigned h() const { return height; }
const Geometry operator()() const { return { x(), y(), w(), h() }; }
private:
unsigned pos() const { return j * cols + i; }
private:
unsigned i, j, cols, rows, H, width, height, max, lm, tm;
};
class vid::IView {
public:
typedef std::shared_ptr<IView> pointer;
IView(unsigned x, unsigned y,
unsigned w, unsigned h) :
xm(x), ym(y),
wm(w), hm(h) {}
public:
virtual void draw() = 0;
public:
void x(unsigned x) { this->xm = x; }
unsigned x( ) const { return xm; }
void y(unsigned y) { this->ym = ym; }
unsigned y( ) const { return ym; }
void h(unsigned h) { this->hm = hm; }
unsigned h( ) const { return hm; }
void w(unsigned w) { this->wm = wm; }
unsigned w( ) const { return wm; }
virtual void resize(const ViewPlacerEx &vp) { resize(vp()); }
virtual void resize(const Geometry &);
private:
unsigned xm;
unsigned ym;
unsigned wm;
unsigned hm;
};
class vid::StatPanel : public vid::IView {
public:
typedef std::shared_ptr<StatPanel> pointer;
StatPanel(unsigned x, unsigned y,
unsigned w, unsigned h) : IView(x,y,w,h) {}
public:
virtual void draw();
};
#include "rec.h"
class vid::CamViewStub : public vid::IView {
public:
CamViewStub(unsigned x, unsigned y,
unsigned w, unsigned h) : IView(x,y,w,h) {}
virtual void draw();
};
class vid::CamViewTest : public vid::IView {
enum class VCoord {
TEX_S,
TEX_T,
VRT_X,
VRT_Y,
VRT_Z,
COORD_NUM
};
#define VERTEX_NUM 4
#define VVAL(i,f) view.get()[i * static_cast<int>(VCoord::COORD_NUM) + static_cast<int>(f)]
public:
CamViewTest(const Geometry &g,
IFrameReceiverSPtr receiver=IFrameReceiverSPtr()) :
IView(g.x, g.y, g.w, g.h),
tex(0),
receiver(receiver)
{
init();
}
CamViewTest(unsigned x, unsigned y,
unsigned w, unsigned h,
IFrameReceiverSPtr receiver=IFrameReceiverSPtr()) :
IView(x, y, w, h),
tex(0),
receiver(receiver)
{
init();
}
~CamViewTest()
{
glDeleteTextures(1, &tex);
}
public:
virtual void draw();
virtual void resize(const Geometry &);
protected:
void draw_tex();
void update_vertexes();
private:
void init();
private:
GLuint tex;
std::shared_ptr<GLfloat> view;
DecImgParams img_geom;
ImageType last_type;
protected:
IFrameReceiverSPtr receiver;
};
class vid::MainView : public Fl_Gl_Window {
public:
MainView(int W, int H,
unsigned cols, unsigned rows,
const char *l=0,
unsigned left_margins=MW_OFFSET, unsigned right_margins=MW_OFFSET,
unsigned top_margins=MW_OFFSET, unsigned bottom_margins=MW_OFFSET );
public:
void draw();
static int run(int, char **);
static int run_test( IFrameReceiver::pointer rec, StreamerSPtr stream, int, char **);
unsigned rows( ) const;
void rows(unsigned) ;
unsigned cols( ) const;
void cols(unsigned) ;
// void set_cell(unsigned, unsigned, IView::pointer);
void set_test_cell(unsigned, unsigned, IFrameReceiverSPtr);
private:
void reinit_screen();
void reinit_views();
private:
unsigned c, r;
std::vector<IView::pointer> cviews;
StatPanel::pointer stat;
unsigned left_marg;
unsigned right_marg;
unsigned top_marg;
unsigned bottom_marg;
};
#endif