rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[goodguy/history.git] / cinelerra-5.1 / cinelerra / signalstatus.C
1 #include "bctitle.h"
2 #include "colors.h"
3 #include "devicedvbinput.h"
4 #include "fonts.h"
5 #include "signalstatus.h"
6
7 #include <unistd.h>
8
9
10 SignalStatus::SignalStatus(BC_WindowBase *wdw, int x, int y)
11  : BC_SubWindow(x, y, 100, 35)
12 {
13         this->wdw = wdw;
14         dvb_input = 0;
15
16         channel_title = 0;
17         lck_x = lck_y = 0;  
18         crr_x = crr_y = 0;  
19         pwr_x = pwr_y = 0;  
20         snr_x = snr_y = 0;  
21         ber_x = ber_y = 0;  
22         unc_x = unc_y = 0;  
23 }
24
25 SignalStatus::~SignalStatus()
26 {
27         if( dvb_input )
28                 dvb_input->set_signal_status(0);
29 }
30
31
32 void SignalStatus::create_objects()
33 {
34         clear_box(0,0,get_w(),get_h());
35         int x = 0, y = 0;
36         channel_title = new BC_Title(x, y, " ", SMALLFONT, GREEN);
37         add_subwindow(channel_title);
38         y += channel_title->get_h();
39         BC_Title *title;
40         add_subwindow(title = new BC_Title(x, y, "lk:", SMALLFONT, YELLOW));
41         lck_x = x + title->get_w() + pad0;
42         lck_y = y + pad0;
43         int x1 = lck_x + lck_w + pad1;
44         int y1 = y + title->get_h();
45         add_subwindow(title = new BC_Title(x, y1, "cr:", SMALLFONT, YELLOW));
46         crr_x = lck_x;
47         crr_y = y1 + pad0;
48         add_subwindow(title = new BC_Title(x1, y, "pwr", SMALLFONT, YELLOW));
49         pwr_x = x1 + title->get_w() + pad0;
50         pwr_y = y + pad0;
51         snr_x = pwr_x;
52         snr_y = pwr_y + pwr_h;
53         add_subwindow(title = new BC_Title(x1, y1, "err", SMALLFONT, YELLOW));
54         ber_x = pwr_x;
55         ber_y = y1 + pad0;
56         unc_x = ber_x;
57         unc_y = ber_y + ber_h;
58 }
59
60 int SignalStatus::calculate_w(BC_WindowBase *wdw)
61 {
62         return BC_Title::calculate_w(wdw, "lk:", SMALLFONT) + pad0 + lck_w + pad1 +
63                 BC_Title::calculate_w(wdw, "pwr", SMALLFONT) + pad0 + pwr_w;
64 }
65
66 int SignalStatus::calculate_h(BC_WindowBase *wdw)
67 {
68         return 3*BC_Title::calculate_h(wdw, "lk:", SMALLFONT);
69 }
70
71 void SignalStatus::update_lck(int v)
72 {
73         set_color(v>0 ? GREEN : RED);
74         draw_box(lck_x, lck_y, lck_w, lck_h);
75 }
76
77 void SignalStatus::update_crr(int v)
78 {
79         set_color(v>0 ? GREEN : RED);
80         draw_box(crr_x, crr_y, crr_w, crr_h);
81 }
82
83 void SignalStatus::update_pwr(int v)
84 {
85         if( v < 0 ) v = 0;
86         int w0 = (v*pwr_w) / 65535, w1 = pwr_w-w0;
87         if( w0 > 0 ) { set_color(GREEN); draw_box(pwr_x, pwr_y, w0, pwr_h); }
88         if( w1 > 0 ) clear_box(pwr_x+w0, pwr_y, w1, pwr_h);
89 }
90
91 void SignalStatus::update_snr(int v)
92 {
93         if( v < 0 ) v = 0;
94         int w0 = (v*snr_w) / 65535, w1 = pwr_w-w0;
95         if( w0 > 0 ) { set_color(BLUE); draw_box(snr_x, snr_y, w0, snr_h); }
96         if( w1 > 0 ) clear_box(snr_x+w0, snr_y, w1, snr_h);
97 }
98
99 void SignalStatus::update_ber(int v)
100 {
101         if( v < 0 ) v = 0;
102         int b = 0;
103         while( v > 0 ) { ++b; v>>=1; }
104         int w0 = (ber_w*b)/16, w1 = ber_w-w0;
105         if( w0 > 0 ) { set_color(YELLOW); draw_box(ber_x, ber_y, w0, ber_h); }
106         if( w1 > 0 ) clear_box(ber_x+w0, ber_y, w1, ber_h);
107 }
108
109 void SignalStatus::update_unc(int v)
110 {
111         if( v < 0 ) v = 0;
112         int b = 0;
113         while( v > 0 ) { ++b; v>>=1; }
114         int w0 = (unc_w*b)/16, w1 = unc_w-w0;
115         if( w0 > 0 ) { set_color(RED); draw_box(unc_x, unc_y, w0, unc_h); }
116         if( w1 > 0 ) clear_box(unc_x+w0, unc_y, w1, unc_h);
117 }
118
119
120 void SignalStatus::update()
121 {
122         channel_title->update(dvb_input->channel_title());
123         update_lck(dvb_input->signal_lck);  update_crr(dvb_input->signal_crr);
124         update_pwr(dvb_input->signal_pwr);  update_snr(dvb_input->signal_snr);
125         update_ber(dvb_input->signal_ber);  update_unc(dvb_input->signal_unc);
126         flash();
127 }
128