void create_box(GtkWidget *window)
{
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *box[4];
GtkWidget *table[3];
GtkDataboxGraph *graph;
GtkWidget separator;
GdkColor color;
gint i;
gint signal_idle = 0;
box1 = gtk_vbox_new(FALSE, 0);
gtk_container_add( GTK_CONTAINER(window), box1);
/* Create the databoxes */
for( i = 0; i<3; i++)
{
/* Create a GtkDatabox widget along with scrollbars and rulers */
gtk_databox_create_box_with_scrollbars_and_rulers (&box[i], &table[i],
TRUE, TRUE, TRUE, TRUE);
gtk_box_pack_start (GTK_BOX (box1), table[i], TRUE, TRUE, 0);
}
// To make cross lines on the boxes
color.red = 32768;
color.green = 32768;
color.blue = 32768;
graph = gtk_databox_cross_simple_new (&color, 0);
for( i = 0; i<3; i++)
{
gtk_databox_graph_add (GTK_DATABOX (box[i]), graph);
}
// To fill up the boxes with black color
color.red = 0;
color.green = 0;
color.blue = 0;//32768;
for( i = 0; i<3; i++)
{
gtk_widget_modify_bg (box[i], GTK_STATE_NORMAL, &color);
}
// Display signals on boxes
for( i = 0; i<3; i++)
{
disp_signal(box[i],color,graph);
signal_idle = g_idle_add ((GSourceFunc) signal_idle_func, box[i]);
}
}
And following functions for displaying signal called from previous function......
Here SignalX and SignalY are static variable intialized in beginning of program...
void disp_signal(GtkWidget *box, GdkColor color, GtkDataboxGraph *graph )
{
gint i;
signal_frequency = 0;
signal_frequency = 3. * G_PI / 2.;
signal_counter = 0;
#if 1 /* For testing purpose putted here replace with suitable code later */
signalX = g_new0 (gfloat, POINTS);
signalY = g_new0 (gfloat, POINTS);
for (i = 0; i < POINTS; i++)
{
signalX[i] = 100. * sin (i * 4 * G_PI / POINTS);
signalY[i] = 100. * cos (i * 4 * G_PI / POINTS);
}
color.red = 65535;
color.green = 65535;
color.blue = 0;
graph = gtk_databox_lines_new (POINTS, signalX, signalY, &color, 1);
gtk_databox_graph_add (GTK_DATABOX (box), graph);
gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
#endif
}
static gboolean
signal_idle_func (GtkDatabox * box)
{
gfloat freq;
gfloat off;
gint i;
if (!GTK_IS_DATABOX (box))
return FALSE;
signal_frequency += 0.001;
off = signal_counter * 4 * G_PI / POINTS;
freq = 14 + 10 * sin (signal_frequency);
for (i = 0; i < POINTS; i++)
{
signalX[i] = 100. * sin (i * 4 * G_PI / POINTS + off);
signalY[i] = 100. * cos (i * freq * G_PI / POINTS + off);
}
gtk_databox_redraw (GTK_DATABOX (box));
return TRUE;
}
Regards,
Nisha