11 VIcon(int vw, int vh, double rate)
15 this->frame_rate = rate;
16 this->cycle_start = 0;
30 add_image(VFrame *frm, int ww, int hh, int vcmdl)
32 VIFrame *vifrm = new VIFrame(ww, hh, vcmdl);
34 img->transfer_from(frm);
39 draw_vframe(BC_WindowBase *wdw, int x, int y)
41 wdw->draw_vframe(frame(), x,y, vw,vh);
44 VIcon *VIconThread::low_vicon()
46 if( !t_heap.size() ) return 0;
47 VIcon *vip = t_heap[0];
52 void VIconThread::remove_vicon(int i)
54 int sz = t_heap.size();
55 for( int k; (k=2*(i+1)) < sz; i=k ) {
56 if( t_heap[k]->age > t_heap[k-1]->age ) --k;
57 t_heap[i] = t_heap[k];
59 VIcon *last = t_heap[--sz];
60 t_heap.remove_number(sz);
61 double age = last->age;
62 for( int k; i>0 && age<t_heap[k=(i-1)/2]->age; i=k )
63 t_heap[i] = t_heap[k];
69 VIconThread(BC_WindowBase *wdw, int vw, int vh)
73 this->view_win = 0; this->vicon = 0;
74 this->view_w = vw; this->view_h = vh;
76 draw_lock = new Condition(0, "VIconThread::draw_lock", 1);
78 this->refresh_rate = VICON_RATE;
89 if( Thread::running() ) {
93 t_heap.remove_all_objects();
101 wdw->lock_window("VIconThread::start_drawing");
103 wdw->set_active_subwindow(view_win);
104 if( interrupted < 0 )
107 wdw->unlock_window();
113 wdw->lock_window("VIconThread::stop_drawing");
117 wdw->unlock_window();
120 int VIconThread::keypress_event(int key)
122 if( key != ESC ) return 0;
127 int ViewPopup::button_press_event()
129 vt->set_view_popup(0);
134 visible(VIcon *vicon, int x, int y)
136 if( vicon->hidden ) return false;
138 int my = y + vicon->vh;
139 if( my <= y0 ) return false;
140 int y1 = y0 + wdw->get_h();
141 if( y >= y1 ) return false;
143 int mx = x + vicon->vw;
144 if( mx <= x0 ) return false;
145 int x1 = x0 + wdw->get_w();
146 if( x >= x1 ) return false;
150 int ViewPopup::keypress_event()
152 int key = get_keypress();
153 return vt->keypress_event(key);
155 ViewPopup::ViewPopup(VIconThread *vt, VFrame *frame, int x, int y, int w, int h)
156 : BC_Popup(vt->wdw, x, y, w, h, BLACK)
161 ViewPopup::~ViewPopup()
163 vt->wdw->set_active_subwindow(0);
166 void ViewPopup::draw_vframe(VFrame *frame)
168 BC_WindowBase::draw_vframe(frame, 0,0, get_w(),get_h());
171 ViewPopup *VIconThread::new_view_window(VFrame *frame)
173 int wx = viewing->get_vx() - view_w, rx = 0;
174 int wy = viewing->get_vy() - view_h, ry = 0;
175 wdw->get_root_coordinates(wx, wy, &rx, &ry);
176 ViewPopup *vwin = new ViewPopup(this, frame, rx, ry, view_w, view_h);
177 wdw->set_active_subwindow(vwin);
184 for( int i=t_heap.size(); --i>=0; ) t_heap[i]->reset();
186 img_dirty = win_dirty = 0;
189 void VIconThread::add_vicon(VIcon *vip)
191 double age = vip->age;
192 int i = t_heap.size(); t_heap.append(vip);
193 for( int k; i>0 && age<t_heap[(k=(i-1)/2)]->age; i=k )
194 t_heap[i] = t_heap[k];
198 int VIconThread::del_vicon(VIcon *&vicon)
200 int i = t_heap.size();
201 while( --i >= 0 && t_heap[i] != vicon );
202 if( i < 0 ) return 0;
204 delete vicon; vicon = 0;
208 void VIconThread::set_view_popup(VIcon *vicon)
216 delete view_win; view_win = 0;
217 if( (viewing=vicon) != 0 ) {
218 VFrame *frame = viewing->frame();
219 view_win = new_view_window(frame);
220 view_win->show_window();
222 wdw->set_active_subwindow(view_win);
230 for( int i=0; i<t_heap.size(); ++i )
237 if( !img_dirty && !win_dirty ) return;
238 if( img_dirty ) wdw->flash();
239 if( win_dirty && view_win ) view_win->flash();
240 win_dirty = img_dirty = 0;
246 int x = vicon->get_vx(), y = vicon->get_vy();
247 int draw_img = visible(vicon, x, y);
248 int draw_win = view_win && viewing == vicon ? 1 : 0;
249 if( !draw_img && !draw_win ) return 0;
250 if( !vicon->frame() ) return 0;
252 vicon->draw_vframe(wdw, x, y);
256 view_win->draw_vframe(vicon->frame());
266 draw_lock->lock("VIconThread::run 0");
268 wdw->lock_window("BC_WindowBase::run 1");
271 int64_t seq_no = 0, now = 0;
272 int64_t draw_flash = 1000 / refresh_rate;
273 while( !interrupted ) {
274 if( viewing != vicon )
276 VIcon *next = low_vicon();
277 while( next && next->age < draw_flash ) {
278 now = timer->get_difference();
279 if( now >= draw_flash ) break;
281 if( !next->seq_no ) next->cycle_start = now;
282 int64_t ref_no = (now - next->cycle_start) / 1000. * refresh_rate;
283 int count = ref_no - next->seq_no;
284 if( count < 1 ) count = 1;
285 ref_no = next->seq_no + count;
286 next->age = next->cycle_start + 1000. * ref_no / refresh_rate;
287 if( !next->set_seq_no(ref_no) )
288 next->age = now + 1000.;
294 if( draw_flash < now+1 )
296 wdw->unlock_window();
297 while( !interrupted ) {
298 now = timer->get_difference();
299 int64_t ms = draw_flash - now;
301 if( ms > 100 ) ms = 100;
304 wdw->lock_window("BC_WindowBase::run 2");
305 now = timer->get_difference();
306 int64_t late = now - draw_flash;
307 if( late < 1000 ) flash();
308 int64_t ref_no = now / 1000. * refresh_rate;
309 int64_t count = ref_no - seq_no;
310 if( count < 1 ) count = 1;
312 draw_flash = seq_no * 1000. / refresh_rate;
314 if( viewing != vicon )
318 wdw->unlock_window();
322 void VIcon::dump(const char *dir)
325 for( int i=0; i<images.size(); ++i ) {
326 char fn[1024]; sprintf(fn,"%s/img%05d.png",dir,i);
328 VFrame *img = *images[i];