@@ -83,6 +83,8 @@ struct offset_data {
8383 int ac_coupled ;
8484};
8585
86+ GtkWidget * chan_buttons [16 ] = {NULL };
87+
8688static void init_chan_sel_window (void );
8789static void init_chan_info_window (void );
8890static void init_vert_info_window (void );
@@ -92,7 +94,6 @@ static void selection_changed(GtkTreeSelection *selection, char *name);
9294static void selection_made (GtkTreeView * treeview , GtkTreePath * path ,
9395 GtkTreeViewColumn * col , GtkWidget * dialog );
9496static void change_source_button (GtkWidget * widget , gpointer gdata );
95- static void channel_off_button (GtkWidget * widget , gpointer gdata );
9697static void offset_button (GtkWidget * widget , gpointer gdata );
9798static gboolean dialog_set_offset (int chan_num );
9899static void scale_changed (GtkAdjustment * adj , gpointer gdata );
@@ -103,7 +104,7 @@ static void chan_sel_button(GtkWidget * widget, gpointer gdata);
103104
104105/* helper functions */
105106static void write_chan_config (FILE * fp , scope_chan_t * chan );
106- static void style_with_css (GtkWidget * widget , int ( * color_arr )[ 3 ] );
107+ static void style_with_css (GtkWidget * widget , int color_index );
107108
108109/***********************************************************************
109110* PUBLIC FUNCTIONS *
@@ -519,37 +520,31 @@ void write_vert_config(FILE *fp)
519520* LOCAL FUNCTIONS *
520521************************************************************************/
521522
522- extern int normal_colors [16 ][3 ], selected_colors [ 16 ][ 3 ] ;
523+ extern int normal_colors [16 ][3 ];
523524static void init_chan_sel_window (void )
524525{
525526 scope_vert_t * vert ;
526527 GtkWidget * button ;
527528 long n ;
528- int j ;
529- int color_array [2 ][3 ];
530529 gchar buf [5 ];
531530
532531 vert = & (ctrl_usr -> vert );
533532 for (n = 0 ; n < 16 ; n ++ ) {
534- /* fill array with color values */
535- for (j = 0 ; j < 3 ; j ++ ) {
536- color_array [0 ][j ] = normal_colors [n ][j ];
537- color_array [1 ][j ] = selected_colors [n ][j ];
538- }
539- snprintf (buf , 4 , "%ld" , n + 1 );
540- /* define the button */
541- button = gtk_toggle_button_new_with_label (buf );
542-
543- style_with_css (button , color_array );
544- /* put it in the window */
545- gtk_box_pack_start (GTK_BOX (ctrl_usr -> chan_sel_win ), button , TRUE,
546- TRUE, 0 );
547- gtk_widget_show (button );
548- /* hook a callback function to it */
549- g_signal_connect (button , "clicked" ,
550- G_CALLBACK (chan_sel_button ), (gpointer ) n + 1 );
551- /* save the button pointer */
552- vert -> chan_sel_buttons [n ] = button ;
533+ snprintf (buf , 4 , "%ld" , n + 1 );
534+ /* define the button */
535+ button = gtk_toggle_button_new_with_label (buf );
536+ chan_buttons [n ] = button ;
537+
538+ style_with_css (button , n );
539+ /* put it in the window */
540+ gtk_box_pack_start (GTK_BOX (ctrl_usr -> chan_sel_win ), button , TRUE,
541+ TRUE, 0 );
542+ gtk_widget_show (button );
543+ /* hook a callback function to it */
544+ g_signal_connect (button , "clicked" ,
545+ G_CALLBACK (chan_sel_button ), (gpointer ) n + 1 );
546+ /* save the button pointer */
547+ vert -> chan_sel_buttons [n ] = button ;
553548 }
554549}
555550
@@ -595,7 +590,6 @@ static void init_vert_info_window(void)
595590{
596591 scope_vert_t * vert ;
597592 GtkWidget * hbox , * vbox ;
598- GtkWidget * button ;
599593
600594 vert = & (ctrl_usr -> vert );
601595
@@ -645,14 +639,6 @@ static void init_vert_info_window(void)
645639 g_signal_connect (vert -> offset_button , "clicked" ,
646640 G_CALLBACK (offset_button ), NULL );
647641 gtk_widget_show (vert -> offset_button );
648- /* a button to turn off the channel */
649- button = gtk_button_new_with_label (_ ("Chan Off" ));
650- gtk_box_pack_start (GTK_BOX (ctrl_usr -> vert_info_win ), button , FALSE, FALSE,
651- 0 );
652- /* turn off the channel if button is clicked */
653- g_signal_connect (button , "clicked" ,
654- G_CALLBACK (channel_off_button ), NULL );
655- gtk_widget_show (button );
656642}
657643
658644static void scale_changed (GtkAdjustment * adj , gpointer gdata )
@@ -804,27 +790,28 @@ static void chan_sel_button(GtkWidget * widget, gpointer gdata)
804790 chan_num = (long ) gdata ;
805791 chan = & (ctrl_usr -> chan [chan_num - 1 ]);
806792
807- if (ignore_click != 0 ) {
808- ignore_click = 0 ;
809- return ;
793+ if (ignore_click ) {
794+ ignore_click = 0 ;
795+ return ;
810796 }
811797 if (vert -> chan_enabled [chan_num - 1 ] == 0 ) {
812- /* channel is disabled, want to enable it */
813- if (ctrl_shm -> state != IDLE ) {
814- /* acquisition in progress, must restart it */
798+ /* channel is disabled, want to enable it */
799+
800+ if (ctrl_shm -> state != IDLE ) {
801+ /* acquisition in progress, must restart it */
815802 prepare_scope_restart ();
816- }
817- count = 0 ;
818- for (n = 0 ; n < 16 ; n ++ ) {
819- if (vert -> chan_enabled [n ]) {
820- count ++ ;
821- }
822- }
823- if (count >= ctrl_shm -> sample_len ) {
824- /* max number of channels already enabled */
825- /* force the button to pop back out */
826- ignore_click = 1 ;
827- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget ), FALSE);
803+ }
804+ count = 0 ;
805+ for (n = 0 ; n < 16 ; n ++ ) {
806+ if (vert -> chan_enabled [n ]) {
807+ count ++ ;
808+ }
809+ }
810+ if (count >= ctrl_shm -> sample_len ) {
811+ /* max number of channels already enabled */
812+ /* force the button to pop back out */
813+ ignore_click = 1 ;
814+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget ), FALSE);
828815 dialog = gtk_message_dialog_new (GTK_WINDOW (ctrl_usr -> main_win ),
829816 GTK_DIALOG_MODAL ,
830817 GTK_MESSAGE_INFO ,
@@ -837,42 +824,38 @@ static void chan_sel_button(GtkWidget * widget, gpointer gdata)
837824 "the record length to allow for more channels" ));
838825 gtk_dialog_run (GTK_DIALOG (dialog ));
839826 gtk_widget_destroy (dialog );
840- return ;
841- }
842- if (chan -> name == NULL ) {
843- /* need to assign a source */
844- if (dialog_select_source (chan_num ) != TRUE) {
845- /* user failed to assign a source */
846- /* force the button to pop back out */
847- ignore_click = 1 ;
848- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget ), FALSE);
849- return ;
850- }
851- }
852- vert -> chan_enabled [chan_num - 1 ] = 1 ;
827+ return ;
828+ }
829+ if (chan -> name == NULL ) {
830+ /* need to assign a source */
831+
832+ if (dialog_select_source (chan_num ) != TRUE) {
833+ /* user failed to assign a source */
834+ /* force the button to pop back out */
835+ ignore_click = 1 ;
836+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget ), FALSE);
837+ return ;
838+ }
839+ }
840+ vert -> chan_enabled [chan_num - 1 ] = 1 ;
841+ /* make chan_num the selected channel */
842+ vert -> selected = chan_num ;
843+ channel_changed ();
844+ } else if (vert -> selected == chan_num ) {
845+ /* a click on an already active channel turns it off */
846+ set_channel_off (chan_num );
847+ ignore_click = 0 ;
853848 } else {
854- /* channel was already enabled, user wants to select it */
855- /* button should stay down, so we force it */
856- ignore_click = 1 ;
857- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget ), TRUE);
858- }
859- if (vert -> selected != chan_num ) {
860- /* make chan_num the selected channel */
861- vert -> selected = chan_num ;
862- channel_changed ();
849+ /* channel was already enabled, user wants to select it */
850+ /* button should stay down, so we force it */
851+ ignore_click = 1 ;
852+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget ), TRUE);
853+ /* make chan_num the selected channel */
854+ vert -> selected = chan_num ;
855+ channel_changed ();
863856 }
864857}
865858
866- static void channel_off_button (GtkWidget * widget , gpointer gdata )
867- {
868- scope_vert_t * vert ;
869- int chan_num ;
870-
871- vert = & (ctrl_usr -> vert );
872- chan_num = vert -> selected ;
873- set_channel_off (chan_num );
874- }
875-
876859static void change_source_button (GtkWidget * widget , gpointer gdata )
877860{
878861 int chan_num ;
@@ -1083,19 +1066,29 @@ void channel_changed(void)
10831066 GtkAdjustment * adj ;
10841067 gchar * name ;
10851068 gchar buf1 [BUFLEN + 1 ], buf2 [BUFLEN + 1 ];
1086-
1069+ static int last_channel = 0 ;
10871070 vert = & (ctrl_usr -> vert );
1071+ /* add a name to apply CSS for highlighted channel */
1072+ if (last_channel != vert -> selected ) {
1073+ if (last_channel ) {
1074+ gtk_widget_set_name (chan_buttons [last_channel - 1 ],"" );
1075+ }
1076+ if (vert -> selected ) {
1077+ gtk_widget_set_name (chan_buttons [vert -> selected - 1 ],"selected" );
1078+ }
1079+ last_channel = vert -> selected ;
1080+ }
10881081 if ((vert -> selected < 1 ) || (vert -> selected > 16 )) {
1089- gtk_label_set_text_if (vert -> scale_label , "----" );
1090- gtk_label_set_text_if (vert -> chan_num_label , "--" );
1091- gtk_label_set_text_if (vert -> source_name_label , "------" );
1092- request_display_refresh (1 );
1093- return ;
1082+ gtk_label_set_text_if (vert -> scale_label , "----" );
1083+ gtk_label_set_text_if (vert -> chan_num_label , "--" );
1084+ gtk_label_set_text_if (vert -> source_name_label , "------" );
1085+ request_display_refresh (1 );
1086+ return ;
10941087 }
10951088 chan = & (ctrl_usr -> chan [vert -> selected - 1 ]);
10961089 /* set position slider based on new channel */
10971090 gtk_adjustment_set_value (GTK_ADJUSTMENT (vert -> pos_adj ),
1098- chan -> position * VERT_POS_RESOLUTION );
1091+ chan -> position * VERT_POS_RESOLUTION );
10991092 /* set scale slider based on new channel */
11001093 adj = GTK_ADJUSTMENT (vert -> scale_adj );
11011094 gtk_adjustment_set_lower (adj , chan -> min_index );
@@ -1108,7 +1101,7 @@ void channel_changed(void)
11081101 gtk_label_set_text_if (vert -> source_name_label , name );
11091102 /* update the offset display */
11101103 if (chan -> data_type == HAL_BIT ) {
1111- snprintf (buf1 , BUFLEN , "----" );
1104+ snprintf (buf1 , BUFLEN , "----" );
11121105 } else {
11131106 if (chan -> ac_offset ) {
11141107 snprintf (buf1 , BUFLEN , "(AC)" );
@@ -1175,20 +1168,23 @@ static void write_chan_config(FILE *fp, scope_chan_t *chan)
11751168/*
11761169 * Inline css, set color to channel select buttons.
11771170 */
1178- static void style_with_css (GtkWidget * widget , int ( * color_arr )[ 3 ] )
1171+ static void style_with_css (GtkWidget * widget , int color_index )
11791172{
11801173 GtkStyleContext * context ;
11811174 GtkCssProvider * provider ;
11821175
1183- char buf [180 ];
1184-
1185- snprintf (buf , sizeof (buf ), "* {background: none;}\n"
1186- "*:checked {background: rgb(%d,%d,%d);}\n"
1187- "*:hover {background: rgb(%d,%d,%d);}\n"
1188- "*:active {background: rgb(%d,%d,%d);}" ,
1189- color_arr [0 ][0 ], color_arr [0 ][1 ], color_arr [0 ][2 ],
1190- color_arr [1 ][0 ], color_arr [1 ][1 ], color_arr [1 ][2 ],
1191- color_arr [0 ][0 ], color_arr [0 ][1 ], color_arr [0 ][2 ]);
1176+ char buf [270 ];
1177+ snprintf (buf , sizeof (buf ), "* {margin: 1px; border-style:solid; border-width: 2px;}\n"
1178+ "#selected {border-color: black; font-weight: bold;}\n"
1179+ "*:checked, *:active {background: rgb(%d,%d,%d);}\n"
1180+ "*:hover {background: rgba(%d,%d,%d,0.3);}\n"
1181+ "*:hover#selected {background: rgba(%d,%d,%d,0.6);}\n" ,
1182+ normal_colors [color_index ][0 ],normal_colors [color_index ][1 ],
1183+ normal_colors [color_index ][2 ],
1184+ normal_colors [color_index ][0 ],normal_colors [color_index ][1 ],
1185+ normal_colors [color_index ][2 ],
1186+ normal_colors [color_index ][0 ],normal_colors [color_index ][1 ],
1187+ normal_colors [color_index ][2 ]);
11921188
11931189 provider = gtk_css_provider_new ();
11941190 context = gtk_widget_get_style_context (widget );
0 commit comments