11 VIcon(int w, int h, double rate)
15 this->frame_rate = rate;
35 add_image(VFrame *frm, int ww, int hh, int vcmdl)
37 VIFrame *vifrm = new VIFrame(ww, hh, vcmdl);
39 img->transfer_from(frm);
44 draw_vframe(VIconThread *vt, BC_WindowBase *wdw, int x, int y)
46 VFrame *vfrm = frame();
48 int sx0 = 0, sx1 = sx0 + vt->vw;
49 int sy0 = 0, sy1 = sy0 + vt->vh;
50 int dx0 = x, dx1 = dx0 + w;
51 int dy0 = y, dy1 = dy0 + h;
52 if( (x=vt->draw_x0-dx0) > 0 ) { sx0 += (x*vt->vw)/w; dx0 = vt->draw_x0; }
53 if( (x=dx1-vt->draw_x1) > 0 ) { sx1 -= (x*vt->vw)/w; dx1 = vt->draw_x1; }
54 if( (y=vt->draw_y0-dy0) > 0 ) { sy0 += (y*vt->vh)/h; dy0 = vt->draw_y0; }
55 if( (y=dy1-vt->draw_y1) > 0 ) { sy1 -= (y*vt->vh)/h; dy1 = vt->draw_y1; }
56 int sw = sx1 - sx0, sh = sy1 - sy0;
57 int dw = dx1 - dx0, dh = dy1 - dy0;
58 if( dw > 0 && dh > 0 && sw > 0 && sh > 0 )
59 wdw->draw_vframe(vfrm, dx0,dy0, dw,dh, sx0,sy0, sw,sh);
63 int VIconThread::cursor_inside(int x, int y)
65 if( !viewing ) return 0;
66 int vx = viewing->get_vx();
67 if( x < vx || x >= vx+vw ) return 0;
68 int vy = viewing->get_vy();
69 if( y < vy || y >= vy+vh ) return 0;
74 set_drawing_area(int x0, int y0, int x1, int y1)
76 draw_x0 = x0; draw_y0 = y0;
77 draw_x1 = x1; draw_y1 = y1;
80 VIcon *VIconThread::low_vicon()
82 if( !t_heap.size() ) return 0;
83 VIcon *vip = t_heap[0];
88 void VIconThread::remove_vicon(int i)
90 int sz = t_heap.size();
91 for( int k; (k=2*(i+1)) < sz; i=k ) {
92 if( t_heap[k]->age > t_heap[k-1]->age ) --k;
93 t_heap[i] = t_heap[k];
95 VIcon *last = t_heap[--sz];
96 t_heap.remove_number(sz);
97 double age = last->age;
98 for( int k; i>0 && age<t_heap[k=(i-1)/2]->age; i=k )
99 t_heap[i] = t_heap[k];
105 VIconThread(BC_WindowBase *wdw, int vw, int vh, int view_w, int view_h)
109 this->vw = vw; this->vh = vh;
110 this->view_w = view_w; this->view_h = view_h;
111 this->view_win = 0; this->vicon = 0;
112 this->viewing = 0; this->solo = 0;
113 this->draw_x0 = 0; this->draw_x1 = wdw->get_w();
114 this->draw_y0 = 0; this->draw_y1 = wdw->get_h();
115 draw_lock = new Condition(0, "VIconThread::draw_lock", 1);
117 this->refresh_rate = VICON_RATE;
118 this->draw_flash = 0;
132 if( Thread::running() ) {
136 t_heap.remove_all_objects();
144 wdw->lock_window("VIconThread::start_drawing");
146 wdw->set_active_subwindow(view_win);
147 if( interrupted < 0 )
150 timer->subtract(-stop_age);
152 wdw->unlock_window();
158 wdw->lock_window("VIconThread::stop_drawing");
162 stop_age = timer->get_difference();
163 wdw->unlock_window();
170 viewing->stop_audio();
175 int VIconThread::keypress_event(int key)
177 if( key != ESC ) return 0;
183 visible(VIcon *vicon, int x, int y)
185 if( vicon->hidden ) return false;
186 if( y+vicon->h <= draw_y0 ) return false;
187 if( y >= draw_y1 ) return false;
188 if( x+vicon->w <= draw_x0 ) return false;
189 if( x >= draw_x1 ) return false;
193 int ViewPopup::keypress_event()
195 int key = get_keypress();
196 return vt->keypress_event(key);
200 ViewPopup::ViewPopup(VIconThread *vt, int x, int y, int w, int h)
201 : BC_Popup(vt->wdw, x, y, w, h, BLACK)
206 ViewPopup::~ViewPopup()
208 vt->wdw->set_active_subwindow(0);
211 ViewPopup *VIconThread::new_view_window()
213 BC_WindowBase *parent = wdw->get_parent();
214 XineramaScreenInfo *info = parent->get_xinerama_info(-1);
215 int cx = info ? info->x_org + info->width/2 : parent->get_root_w(0)/2;
216 int cy = info ? info->y_org + info->height/2 : parent->get_root_h(0)/2;
217 int vx = viewing->get_vx(), rx = 0;
218 int vy = viewing->get_vy(), ry = 0;
219 wdw->get_root_coordinates(vx, vy, &rx, &ry);
220 rx += (rx >= cx ? -view_w+viewing->w/4 : viewing->w-viewing->w/4);
221 ry += (ry >= cy ? -view_h+viewing->h/4 : viewing->h-viewing->h/4);
222 ViewPopup *vwin = new ViewPopup(this, rx, ry, view_w, view_h);
223 wdw->set_active_subwindow(vwin);
231 for( int i=t_heap.size(); --i>=0; ) t_heap[i]->reset();
233 img_dirty = win_dirty = 0;
236 void VIconThread::add_vicon(VIcon *vip)
238 double age = vip->age;
239 int i = t_heap.size(); t_heap.append(vip);
240 for( int k; i>0 && age<t_heap[(k=(i-1)/2)]->age; i=k )
241 t_heap[i] = t_heap[k];
245 int VIconThread::del_vicon(VIcon *vicon)
247 int i = t_heap.size();
248 while( --i >= 0 && t_heap[i] != vicon );
249 if( i < 0 ) return 0;
254 void ViewPopup::draw_vframe(VFrame *frame)
257 BC_WindowBase::draw_vframe(frame, 0,0, get_w(),get_h());
260 void VIconThread::set_view_popup(VIcon *vicon)
262 if( viewing == vicon && !this->vicon ) return;
269 void VIconThread::close_view_popup()
275 update_view(int do_audio)
277 if( viewing ) viewing->stop_audio();
278 delete view_win; view_win = 0;
279 if( (viewing=vicon) != 0 ) {
280 view_win = new_view_window();
281 view_win->draw_vframe(viewing->frame());
283 view_win->show_window();
284 if( do_audio ) vicon->start_audio();
286 wdw->set_active_subwindow(view_win);
290 int VIconThread::zoom_scale(int dir)
292 int view_h = this->view_h;
293 view_h += dir*view_h/10 + dir;
294 bclamp(view_h, 16,512);
295 this->view_h = view_h;
296 this->view_w = view_h * vw/vh;
305 for( int i=0; i<t_heap.size(); ++i )
312 if( !img_dirty && !win_dirty ) return;
313 if( img_dirty ) wdw->flash();
314 if( win_dirty && view_win ) view_win->flash();
315 win_dirty = img_dirty = 0;
321 int x = vicon->get_vx(), y = vicon->get_vy();
322 int draw_img = visible(vicon, x, y);
323 int draw_win = view_win && viewing == vicon ? 1 : 0;
324 if( !draw_img && !draw_win ) return 0;
325 if( !vicon->frame() ) return 0;
327 vicon->draw_vframe(this, wdw, x, y);
331 view_win->draw_vframe(vicon->frame());
337 void VIconThread::hide_vicons(int v)
339 for( int i=0; i<t_heap.size(); ++i ) {
340 t_heap[i]->hidden = v;
345 int VIconThread::show_vicon(VIcon *next)
347 now = timer->get_difference();
348 if( now >= draw_flash ) return 1;
350 if( !next->seq_no ) {
351 next->cycle_start = now;
352 if( next->playing_audio > 0 )
355 int64_t ref_no = (now - next->cycle_start) / 1000. * refresh_rate;
356 int count = ref_no - next->seq_no;
357 if( count < 1 ) count = 1;
358 ref_no = next->seq_no + count;
359 next->age = next->cycle_start + 1000. * ref_no / refresh_rate;
360 if( !next->set_seq_no(ref_no) )
361 next->age = now + 1000.;
369 draw_lock->lock("VIconThread::run 0");
371 wdw->lock_window("BC_WindowBase::run 1");
374 draw_flash = 1000 / refresh_rate;
376 while( !interrupted ) {
377 if( viewing != vicon )
380 VIcon *next = low_vicon();
381 while( next && next->age < draw_flash ) {
382 if( show_vicon(next) ) break;
388 if( draw_flash < now+1 )
393 wdw->unlock_window();
394 while( !interrupted ) {
395 now = timer->get_difference();
396 int64_t ms = draw_flash - now;
398 if( ms > 100 ) ms = 100;
401 wdw->lock_window("BC_WindowBase::run 2");
402 now = timer->get_difference();
403 int64_t late = now - draw_flash;
404 if( late < 1000 ) flash();
405 int64_t ref_no = now / 1000. * refresh_rate;
406 int64_t count = ref_no - seq_no;
407 if( count < 1 ) count = 1;
409 draw_flash = seq_no * 1000. / refresh_rate;
411 if( viewing != vicon )
415 wdw->unlock_window();
420 void VIcon::init_audio(int audio_size)
422 this->audio_size = audio_size;
423 audio_data = new uint8_t[audio_size];
424 memset(audio_data, 0, audio_size);
427 void VIcon::dump(const char *dir)
430 for( int i=0; i<images.size(); ++i ) {
431 char fn[1024]; sprintf(fn,"%s/img%05d.png",dir,i);
433 VFrame *img = *images[i];