24 client_rect_wd = client_width;
25 client_rect_ht = client_height;
27 buffer =
new QImage( client_rect_wd, client_rect_ht, QImage::Format_RGB32 );
29 vis_range_x = client_rect_wd;
34 data_cnt = 10*grid_N*10;
40 pen.setStyle( Qt::SolidLine );
42 brush.setStyle(Qt::SolidPattern);
50 brush.setColor( BKGD_COLOR );
69 void cscroll_graph::init_render_vars(
void )
71 half_buffer_size_wd = client_rect_wd / 2;
72 half_buffer_size_ht = client_rect_ht / 2;
75 grid_view_step_x = (double)client_rect_wd / (
double)grid_N;
76 grid_view_step_y = (double)client_rect_ht / (
double)grid_N;
78 grid_step_x = (double)vis_range_x / (
double)grid_N;
79 grid_step_y = (double)vis_range_y / (
double)grid_N;
81 half_vis_range_x = vis_range_x / 2;
82 half_vis_range_y = vis_range_y / 2;
89 if( rx >= 10*grid_N && rx < (
double)data_cnt )
91 if( vis_range_x != rx )
97 u_msg(
"set_visible_ranges: must be >= %d and < %d", 10*grid_N, data_cnt);
103 if( vis_range_x != ry )
109 u_msg(
"set_visible_ranges: must be >= %d and < %d", 5*grid_N, data_cnt);
143 memset( data.
line[
RA_LINE], 0,
sizeof(
double)*data_cnt );
144 memset( data.
line[
DEC_LINE], 0,
sizeof(
double)*data_cnt );
158 *sx = client_rect_wd;
159 *sy = client_rect_ht;
165 canvas.begin( buffer );
178 void cscroll_graph::refresh(
void )
184 int band1_start, band1_end;
185 int band2_wd, band2_start, band2_end;
192 font_ht_k = canvas.fontMetrics().ascent();
195 canvas.fillRect( 0, 0, client_rect_wd, client_rect_ht, brush);
197 start_idx = (data_idx + data_cnt - vis_range_x) % data_cnt;
199 if( data_idx > start_idx )
202 band1_start = start_idx;
203 band1_end = data_idx;
204 band2_start = band2_end = band2_wd = 0;
210 band1_end = data_idx;
212 band2_wd = data_cnt - start_idx;
213 band2_start = start_idx;
214 band2_end = data_cnt-1;
218 kx = (double)client_rect_wd / vis_range_x;
219 ky = (double)client_rect_ht / vis_range_y;
224 if( client_rect_wd <= vis_range_x )
228 for( k = 0;k < 2;k++ )
230 data_ptr = data.
line[k];
233 pen.setColor( RA_COLOR );
235 pen.setColor( DEC_COLOR );
237 canvas.setPen( pen );
240 px = client_rect_wd;;
241 py = half_buffer_size_ht - (int)(data_ptr[band1_end] * ky);
245 for( i = band1_end, j = 0;i >= band1_start; )
247 y = half_buffer_size_ht - (int)(data_ptr[i] * ky);
250 canvas.drawLine( px, py, x, y );
257 i = band1_end - (int)((
double)j*step);
261 for( i = band2_end, j = 0;i > band2_start; )
263 y = half_buffer_size_ht - (int)(data_ptr[i] * ky);
266 canvas.drawLine( px, py, x, y );
273 i = band2_end - (int)((
double)j*step);
281 for( k = 0;k < 2;k++ )
283 data_ptr = data.
line[k];
286 pen.setColor( RA_COLOR );
288 pen.setColor( DEC_COLOR );
290 canvas.setPen( pen );
294 py = half_buffer_size_ht - (int)(data_ptr[band1_end] * ky);
298 for( i = band1_end, j = 0;i >= band1_start;i--, ++j )
300 y = half_buffer_size_ht - (int)(data_ptr[i] * ky);
301 x = client_rect_wd - (int)((
double)j*step) - 1;
303 canvas.drawLine( px, py, x, y );
312 for( i = band2_end;i > band2_start;i--, ++j )
314 y = half_buffer_size_ht - (int)(data_ptr[i] * ky);
315 x = client_rect_wd - (int)((
double)j*step) - 1;
317 canvas.drawLine( px, py, x, y );
326 need_refresh = false;
333 int grid_column, val;
336 pen.setColor( GRID_COLOR );
337 canvas.setPen( pen );
339 grid_column = data_idx / (int)grid_step_x * (
int)grid_step_x;
340 sx = client_rect_wd - (double)(data_idx % (
int)grid_step_x)*kx;
342 for( i = 0;i < grid_N;++i )
344 x = sx - (double)i*grid_view_step_x;
345 y = (double)i*grid_view_step_y;
347 canvas.drawLine( x, 0, x, client_rect_ht );
351 pen.setColor( WHITE_COLOR );
352 canvas.setPen( pen );
353 canvas.drawLine( 0, y, client_rect_wd, y );
354 pen.setColor( GRID_COLOR );
355 canvas.setPen( pen );
358 canvas.drawLine( 0, y, client_rect_wd, y );
362 pen.setColor( GRID_FONT_COLOR );
363 canvas.setPen( pen );
364 for( i = 0;i < grid_N;++i )
366 x = sx - (double)i*grid_view_step_x;
367 y = (double)i*grid_view_step_y;
369 if( (val = grid_column - i*(
int)grid_step_x) >= 0 )
372 canvas.drawText( x, half_buffer_size_ht + font_ht_k, str );
374 str.setNum( (
int)(half_vis_range_y - grid_step_y*i) );
375 canvas.drawText( 2, y + font_ht_k, str );
386 if( data_idx == data_cnt-1 )
const u_char DEF_GRID_COLOR[3]
const u_char DEF_WHITE_COLOR[3]
const u_char DEF_DEC_COLOR[3]
void u_msg(const char *fmt,...)
const u_char DEF_BKGD_COLOR[3]
const u_char DEF_GRID_FONT_COLOR[3]
const u_char DEF_RA_COLOR[3]