11 VIcon(int vw, int vh, double rate)
15 this->frame_rate = rate;
16 this->cycle_start = 0;
29 add_image(VFrame *frm, int ww, int hh, int vcmdl)
31 VIFrame *vifrm = new VIFrame(ww, hh, vcmdl);
33 img->transfer_from(frm);
38 draw_vframe(BC_WindowBase *wdw, int x, int y)
40 wdw->draw_vframe(frame(), x,y, vw,vh);
43 VIcon *VIconThread::low_vicon()
45 if( !t_heap.size() ) return 0;
46 VIcon *vip = t_heap[0];
51 void VIconThread::remove_vicon(int i)
53 int sz = t_heap.size();
54 for( int k; (k=2*(i+1)) < sz; i=k ) {
55 if( t_heap[k]->age > t_heap[k-1]->age ) --k;
56 t_heap[i] = t_heap[k];
58 VIcon *last = t_heap[--sz];
59 t_heap.remove_number(sz);
60 double age = last->age;
61 for( int k; i>0 && age<t_heap[k=(i-1)/2]->age; i=k )
62 t_heap[i] = t_heap[k];
68 VIconThread(BC_WindowBase *wdw, int vw, int vh)
72 this->view_win = 0; this->vicon = 0;
73 this->view_w = vw; this->view_h = vh;
75 draw_lock = new Condition(0, "VIconThread::draw_lock", 1);
77 this->refresh_rate = VICON_RATE;
88 if( Thread::running() ) {
92 t_heap.remove_all_objects();
100 wdw->lock_window("VIconThread::start_drawing");
102 wdw->set_active_subwindow(view_win);
105 wdw->unlock_window();
111 wdw->lock_window("VIconThread::stop_drawing");
114 wdw->unlock_window();
117 int VIconThread::keypress_event(int key)
119 if( key != ESC ) return 0;
124 int ViewPopup::button_press_event()
126 vt->set_view_popup(0);
131 visible(VIcon *vicon, int x, int y)
134 int my = y + vicon->vh;
135 if( my <= y0 ) return false;
136 int y1 = y0 + wdw->get_h();
137 if( y >= y1 ) return false;
139 int mx = x + vicon->vw;
140 if( mx <= x0 ) return false;
141 int x1 = x0 + wdw->get_w();
142 if( x >= x1 ) return false;
146 int ViewPopup::keypress_event()
148 int key = get_keypress();
149 return vt->keypress_event(key);
151 ViewPopup::ViewPopup(VIconThread *vt, VFrame *frame, int x, int y, int w, int h)
152 : BC_Popup(vt->wdw, x, y, w, h, BLACK)
157 ViewPopup::~ViewPopup()
159 vt->wdw->set_active_subwindow(0);
162 void ViewPopup::draw_vframe(VFrame *frame)
164 BC_WindowBase::draw_vframe(frame, 0,0, get_w(),get_h());
167 ViewPopup *VIconThread::new_view_window(VFrame *frame)
169 int wx = viewing->get_vx() - view_w, rx = 0;
170 int wy = viewing->get_vy() - view_h, ry = 0;
171 wdw->get_root_coordinates(wx, wy, &rx, &ry);
172 ViewPopup *vwin = new ViewPopup(this, frame, rx, ry, view_w, view_h);
173 wdw->set_active_subwindow(vwin);
180 for( int i=t_heap.size(); --i>=0; ) t_heap[i]->reset();
182 img_dirty = win_dirty = 0;
185 void VIconThread::add_vicon(VIcon *vip)
187 double age = vip->age;
188 int i = t_heap.size(); t_heap.append(vip);
189 for( int k; i>0 && age<t_heap[(k=(i-1)/2)]->age; i=k )
190 t_heap[i] = t_heap[k];
194 int VIconThread::del_vicon(VIcon *&vicon)
196 int i = t_heap.size();
197 while( --i >= 0 && t_heap[i] != vicon );
198 if( i < 0 ) return 0;
200 delete vicon; vicon = 0;
204 void VIconThread::set_view_popup(VIcon *vicon)
212 delete view_win; view_win = 0;
213 if( (viewing=vicon) != 0 ) {
214 VFrame *frame = viewing->frame();
215 view_win = new_view_window(frame);
216 view_win->show_window();
218 wdw->set_active_subwindow(view_win);
226 for( int i=0; i<t_heap.size(); ++i )
233 if( !img_dirty && !win_dirty ) return;
234 if( img_dirty ) wdw->flash();
235 if( win_dirty && view_win ) view_win->flash();
236 win_dirty = img_dirty = 0;
242 int x = vicon->get_vx(), y = vicon->get_vy();
243 int draw_img = visible(vicon, x, y);
244 int draw_win = view_win && viewing == vicon ? 1 : 0;
245 if( !draw_img && !draw_win ) return 0;
246 if( !vicon->frame() ) return 0;
248 vicon->draw_vframe(wdw, x, y);
252 view_win->draw_vframe(vicon->frame());
262 draw_lock->lock("VIconThread::run 0");
264 wdw->lock_window("BC_WindowBase::run 1");
268 int64_t seq_no = 0, now = 0;
269 int64_t draw_flash = 1000 / refresh_rate;
270 while( !interrupted ) {
271 if( viewing != vicon )
273 VIcon *next = low_vicon();
274 while( next && next->age < draw_flash ) {
275 now = timer->get_difference();
276 if( now >= draw_flash ) break;
278 if( !next->seq_no ) next->cycle_start = now;
279 int64_t ref_no = (now - next->cycle_start) / 1000. * refresh_rate;
280 int count = ref_no - next->seq_no;
281 if( count < 1 ) count = 1;
282 ref_no = next->seq_no + count;
283 next->age = next->cycle_start + 1000. * ref_no / refresh_rate;
284 if( !next->set_seq_no(ref_no) )
285 next->age = now + 1000.;
291 if( draw_flash < now+1 )
293 wdw->unlock_window();
294 while( !interrupted ) {
295 now = timer->get_difference();
296 int64_t ms = draw_flash - now;
298 if( ms > 100 ) ms = 100;
301 wdw->lock_window("BC_WindowBase::run 2");
302 now = timer->get_difference();
303 int64_t late = now - draw_flash;
304 if( late < 1000 ) flash();
305 int64_t ref_no = now / 1000. * refresh_rate;
306 int64_t count = ref_no - seq_no;
307 if( count < 1 ) count = 1;
309 draw_flash = seq_no * 1000. / refresh_rate;
311 if( viewing != vicon )
315 wdw->unlock_window();
319 void VIcon::dump(const char *dir)
322 for( int i=0; i<images.size(); ++i ) {
323 char fn[1024]; sprintf(fn,"%s/img%05d.png",dir,i);
325 VFrame *img = *images[i];