11 VIcon(int vw, int vh, double rate)
15 this->period = 1000./rate;
28 add_image(VFrame *frm, int ww, int hh, int vcmdl)
30 VFrame *img = new VFrame(ww, hh, vcmdl);
31 img->transfer_from(frm);
36 draw_vframe(BC_WindowBase *wdw, int x, int y)
38 wdw->draw_vframe(frame(), x,y, vw,vh);
41 VIcon *VIconThread::low_vicon()
43 if( !t_heap.size() ) return 0;
44 VIcon *vip = t_heap[0];
49 void VIconThread::remove_vicon(int i)
51 int sz = t_heap.size();
52 for( int k; (k=2*(i+1)) < sz; i=k ) {
53 if( t_heap[k]->age > t_heap[k-1]->age ) --k;
54 t_heap[i] = t_heap[k];
56 VIcon *last = t_heap[--sz];
57 t_heap.remove_number(sz);
58 double age = last->age;
59 for( int k; i>0 && age<t_heap[k=(i-1)/2]->age; i=k )
60 t_heap[i] = t_heap[k];
66 VIconThread(BC_WindowBase *wdw, int vw, int vh)
70 this->view_win = 0; this->vicon = 0;
71 this->view_w = vw; this->view_h = vh;
72 this->viewing = 0; this->draw_flash = 0;
73 draw_lock = new Condition(0, "VIconThread::draw_lock", 1);
85 if( Thread::running() ) {
89 t_heap.remove_all_objects();
97 wdw->lock_window("VIconThread::start_drawing");
100 wdw->unlock_window();
106 wdw->lock_window("VIconThread::stop_drawing");
108 wdw->unlock_window();
111 int VIconThread::keypress_event(int key)
113 if( key != ESC ) return 0;
118 int ViewPopup::button_press_event()
120 vt->set_view_popup(0);
125 visible(VIcon *vicon, int x, int y)
128 int my = y + vicon->vh;
129 if( my <= y0 ) return false;
130 int y1 = y0 + wdw->get_h();
131 if( y >= y1 ) return false;
133 int mx = x + vicon->vw;
134 if( mx <= x0 ) return false;
135 int x1 = x0 + wdw->get_w();
136 if( x >= x1 ) return false;
140 int ViewPopup::keypress_event()
142 int key = get_keypress();
143 return vt->keypress_event(key);
145 ViewPopup::ViewPopup(VIconThread *vt, VFrame *frame, int x, int y, int w, int h)
146 : BC_Popup(vt->wdw, x, y, w, h, BLACK)
151 ViewPopup::~ViewPopup()
153 vt->wdw->set_active_subwindow(0);
156 void ViewPopup::draw_vframe(VFrame *frame)
158 BC_WindowBase::draw_vframe(frame, 0,0, get_w(),get_h());
161 ViewPopup *VIconThread::new_view_window(VFrame *frame)
163 int wx = viewing->get_vx() - view_w, rx = 0;
164 int wy = viewing->get_vy() - view_h, ry = 0;
165 wdw->get_root_coordinates(wx, wy, &rx, &ry);
166 ViewPopup *vwin = new ViewPopup(this, frame, rx, ry, view_w, view_h);
167 wdw->set_active_subwindow(vwin);
174 for( int i=t_heap.size(); --i>=0; ) t_heap[i]->age = 0;
176 img_dirty = win_dirty = 0;
180 void VIconThread::add_vicon(VIcon *vip, double age)
183 int i = t_heap.size(); t_heap.append(vip);
184 for( int k; i>0 && age<t_heap[(k=(i-1)/2)]->age; i=k )
185 t_heap[i] = t_heap[k];
189 int VIconThread::del_vicon(VIcon *&vicon)
191 int i = t_heap.size();
192 while( --i >= 0 && t_heap[i] != vicon );
193 if( i < 0 ) return 0;
195 delete vicon; vicon = 0;
199 void VIconThread::set_view_popup(VIcon *vicon)
207 delete view_win; view_win = 0;
208 if( (viewing=vicon) != 0 ) {
209 VFrame *frame = viewing->frame();
210 view_win = new_view_window(frame);
211 view_win->show_window();
220 for( int i=0; i<t_heap.size(); ++i )
227 if( !img_dirty && !win_dirty ) return;
228 if( img_dirty ) wdw->flash();
229 if( win_dirty ) view_win->flash();
230 win_dirty = img_dirty = 0;
236 int x = vicon->get_vx(), y = vicon->get_vy();
237 int draw_img = visible(vicon, x, y);
238 int draw_win = view_win && viewing == vicon ? 1 : 0;
239 if( !draw_img && !draw_win ) return 0;
241 vicon->draw_vframe(wdw, x, y);
245 view_win->draw_vframe(vicon->frame());
255 draw_lock->lock("VIconThread::run 0");
257 wdw->lock_window("BC_WindowBase::run 1");
261 while( !interrupted ) {
262 if( viewing != vicon )
264 VIcon *next = low_vicon();
266 if( !next->frame() ) {
267 delete next; next = 0;
270 int64_t next_time = next->age;
271 int64_t this_time = timer->get_difference();
272 int64_t msec = this_time - next_time;
273 int count = msec / next->period;
274 int nfrms = count > 0 ? count : 1;
275 if( !next->next_frame(nfrms) )
276 next->age = this_time + 1000;
277 add_vicon(next, next->age);
278 if( msec < 1000 && draw(next) && !draw_flash )
279 draw_flash = next_time;
280 wdw->unlock_window();
281 msec = next_time - timer->get_difference();
282 if( msec < 1 ) msec = 1;
283 while( msec > 0 && !interrupted ) {
284 int ms = msec > 100 ? 100 : msec;
285 Timer::delay(ms); msec -= ms;
287 wdw->lock_window("BC_WindowBase::run 2");
288 if( interrupted ) break;
290 int64_t msec = timer->get_difference() - draw_flash;
291 if( msec < 1000 ) flash();
297 wdw->unlock_window();
301 void VIcon::dump(const char *dir)
304 for( int i=0; i<images.size(); ++i ) {
305 char fn[1024]; sprintf(fn,"%s/img%05d.png",dir,i);
307 images[i]->write_png(fn);