Skip to content

Commit 21b8d3b

Browse files
committed
halscope: optimized coloring of channel buttons
1 parent 5389fa4 commit 21b8d3b

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

src/hal/utils/scope_vert.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void chan_sel_button(GtkWidget * widget, gpointer gdata);
104104

105105
/* helper functions */
106106
static void write_chan_config(FILE *fp, scope_chan_t *chan);
107-
static void style_with_css(GtkWidget *widget, int (*color_arr)[3]);
107+
static void style_with_css(GtkWidget *widget, int color_index);
108108

109109
/***********************************************************************
110110
* PUBLIC FUNCTIONS *
@@ -520,29 +520,22 @@ void write_vert_config(FILE *fp)
520520
* LOCAL FUNCTIONS *
521521
************************************************************************/
522522

523-
extern int normal_colors[16][3], selected_colors[16][3];
523+
extern int normal_colors[16][3];
524524
static void init_chan_sel_window(void)
525525
{
526526
scope_vert_t *vert;
527527
GtkWidget *button;
528528
long n;
529-
int j;
530-
int color_array[2][3];
531529
gchar buf[5];
532530

533531
vert = &(ctrl_usr->vert);
534532
for (n = 0; n < 16; n++) {
535-
/* fill array with color values */
536-
for (j = 0; j < 3; j++) {
537-
color_array[0][j] = normal_colors[n][j];
538-
color_array[1][j] = selected_colors[n][j];
539-
}
540533
snprintf(buf, 4, "%ld", n + 1);
541534
/* define the button */
542535
button = gtk_toggle_button_new_with_label(buf);
543536
chan_buttons[n] = button;
544537

545-
style_with_css(button, color_array);
538+
style_with_css(button, n);
546539
/* put it in the window */
547540
gtk_box_pack_start(GTK_BOX(ctrl_usr->chan_sel_win), button, TRUE,
548541
TRUE, 0);
@@ -1202,20 +1195,20 @@ static void write_chan_config(FILE *fp, scope_chan_t *chan)
12021195
/*
12031196
* Inline css, set color to channel select buttons.
12041197
*/
1205-
static void style_with_css(GtkWidget *widget, int (*color_arr)[3])
1198+
static void style_with_css(GtkWidget *widget, int color_index)
12061199
{
12071200
GtkStyleContext *context;
12081201
GtkCssProvider *provider;
12091202

12101203
char buf[230];
12111204
snprintf(buf, sizeof(buf), "* {margin: 1px; border-style:solid; border-width: 2px;}\n"
12121205
"#selected {border-color: black; font-weight: bold;}\n"
1213-
"*:checked {background: rgb(%d,%d,%d);}\n"
1214-
"*:hover {background: rgb(%d,%d,%d);}\n"
1215-
"*:active {background: rgb(%d,%d,%d);}",
1216-
color_arr[0][0], color_arr[0][1], color_arr[0][2],
1217-
color_arr[1][0], color_arr[1][1], color_arr[1][2],
1218-
color_arr[0][0], color_arr[0][1], color_arr[0][2]);
1206+
"*:checked, *:active {background: rgb(%d,%d,%d);}\n"
1207+
"*:hover {background: rgba(%d,%d,%d,0.3);}\n",
1208+
normal_colors[color_index][0],normal_colors[color_index][1],
1209+
normal_colors[color_index][2],
1210+
normal_colors[color_index][0],normal_colors[color_index][1],
1211+
normal_colors[color_index][2]);
12191212

12201213
provider = gtk_css_provider_new ();
12211214
context = gtk_widget_get_style_context(widget);

0 commit comments

Comments
 (0)