comparison src/rootvis/config_frontend.c @ 900:d985f0dcdeb0 trunk

[svn] - add a starting point for xmms-rootvis port. giacomo will need to finish this up, as my XLib skills are not enough at this time.
author nenolod
date Mon, 26 Mar 2007 01:19:26 -0700
parents
children 30e515b6e651
comparison
equal deleted inserted replaced
899:68508f8cdf25 900:d985f0dcdeb0
1 #include <stdarg.h>
2 #include <string.h>
3
4 #include <rootvis.h>
5
6 #include <config_frontend.h>
7
8 extern GtkWidget *frontend_create_channel(int channel);
9 extern GtkWidget *frontend_create_main(void);
10 extern void frontend_create_colorpicker(struct config_value*);
11
12 void signal_revert(GtkWidget *togglebutton, gpointer data)
13 {
14 config_revert(GPOINTER_TO_INT(data));
15 }
16
17 void signal_save(GtkWidget *togglebutton, gpointer data)
18 {
19 config_save(GPOINTER_TO_INT(data));
20 }
21
22 void signal_show(GtkWidget *togglebutton, gpointer data)
23 {
24 config_show(GPOINTER_TO_INT(data));
25 }
26
27 void signal_hide(GtkWidget *togglebutton, gpointer data)
28 {
29 config_hide(GPOINTER_TO_INT(data));
30 }
31
32 void signal_toggle_colorselector(GtkWidget *w, struct config_value *cvar)
33 {
34 struct rootvis_colorsel* colorsel = cvar->valc.frontend;
35 if (colorsel->window == NULL)
36 frontend_create_colorpicker(cvar);
37 gtk_widget_show(colorsel->window);
38 }
39
40 void signal_colorselector_ok(GtkWidget *w, struct config_value *cvar)
41 {
42 struct rootvis_colorsel* colorsel = cvar->valc.frontend;
43 gtk_color_selection_get_color(GTK_COLOR_SELECTION(colorsel->color_picker), colorsel->color);
44 memcpy(colorsel->saved_color, colorsel->color, COLORSIZE*sizeof(gdouble));
45 frontend_update_color(cvar, 1);
46 gtk_widget_hide(colorsel->window);
47 }
48
49 void signal_colorselector_cancel(GtkWidget *w, struct config_value *cvar)
50 {
51 struct rootvis_colorsel* colorsel = cvar->valc.frontend;
52 memcpy(colorsel->color, colorsel->saved_color, COLORSIZE*sizeof(gdouble));
53 frontend_update_color(cvar, 1);
54 gtk_widget_destroy(colorsel->window);
55 colorsel->window = NULL;
56 }
57
58 void signal_colorselector_update(GtkWidget *w, struct config_value *cvar)
59 {
60 struct rootvis_colorsel* colorsel = cvar->valc.frontend;
61 gtk_color_selection_get_color(GTK_COLOR_SELECTION(colorsel->color_picker), colorsel->color);
62 frontend_update_color(cvar, 1);
63 }
64
65 void color_char2double(unsigned char source[4], gdouble dest[4])
66 {
67 int i;
68 for (i = 0; i < COLORSIZE; ++i)
69 {
70 dest[i] = (double)source[i] / 255.0;
71 }
72 }
73
74 void color_double2char(double source[4], unsigned char dest[4])
75 {
76 int i;
77 for (i = 0; i < COLORSIZE; ++i)
78 {
79 dest[i] = (int)(source[i] * 255.0);
80 }
81 }
82
83 // This was ripped from xmms-iris's config.c.
84 void frontend_update_color(struct config_value *cvar, int system)
85 {
86 struct rootvis_colorsel* colorsel = cvar->valc.frontend;
87 if (system > 0)
88 {
89 threads_lock();
90 color_double2char(colorsel->color, cvar->valc.var);
91 threads_unlock(2);
92 }
93
94 // following is among the dumbest shit I've ever seen. GtkPreview seems to suck a lot!
95 unsigned int i;
96 guchar color_buf[3*30];
97 char red, green, blue;
98 red = colorsel->color[RED]*0xff;
99 green = colorsel->color[GREEN]*0xff;
100 blue = colorsel->color[BLUE]*0xff;
101 for (i = 0; i < 30*3; i += 3) {
102 color_buf[i+RED] = (char) red;
103 color_buf[i+GREEN] = (char) green;
104 color_buf[i+BLUE] = (char) blue;
105 }
106 for (i = 0; i < 30; i++)
107 gtk_preview_draw_row(GTK_PREVIEW(colorsel->preview), color_buf, 0, i, 30);
108 gtk_widget_draw(colorsel->preview, NULL);
109 }
110
111 void frontend_set_color(struct config_value *cvar)
112 {
113 struct rootvis_colorsel* colorsel = cvar->valc.frontend;
114 color_char2double(cvar->valc.var, colorsel->color);
115 memcpy(colorsel->saved_color, colorsel->color, COLORSIZE*sizeof(gdouble));
116 }
117
118 /* following functions catch signals from the gui widgets */
119
120 int signal_window_close(GtkWidget *window, gpointer data)
121 {
122 int number = 2;
123 if (window == widgets.window_channel[0]) number = 0;
124 if (window == widgets.window_channel[1]) number = 1;
125 config_hide(number);
126 return TRUE;
127 }
128
129 void signal_check_toggled(GtkWidget *togglebutton, gpointer data)
130 {
131 printf("%s \n", (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglebutton))) ? "TRUE" : "FALSE");
132 }
133
134 void signal_stereo_toggled(GtkWidget *togglebutton, gpointer data)
135 {
136 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglebutton))) {
137 gtk_label_set_text(widgets.stereo_status[0], "renders left channel");
138 gtk_label_set_text(widgets.stereo_status[1], "renders right channel");
139 } else {
140 gtk_label_set_text(widgets.stereo_status[0], "renders both channels");
141 gtk_label_set_text(widgets.stereo_status[1], "unused / inactive");
142 }
143 }
144
145 void signal_textentry_changed(GtkWidget *entry, gpointer data)
146 {
147 }
148
149 void config_show_channel(int channel) {
150 if (widgets.window_channel[channel] == NULL) {
151 widgets.window_channel[channel] = frontend_create_channel(channel);
152 } else {
153 print_status("raising channel window");
154 gtk_widget_show(widgets.window_channel[channel]);
155 }
156 }
157
158 void config_show(int channel) {
159 if (channel == 2)
160 {
161 if (widgets.window_main == NULL) {
162 widgets.window_main = frontend_create_main();
163 } else {
164 print_status("raising windows");
165 gtk_widget_show(widgets.window_main);
166 if (widgets.window_channel[0] != NULL) {
167 gtk_widget_show(widgets.window_channel[0]);
168 }
169 if (widgets.window_channel[1] != NULL) {
170 gtk_widget_show(widgets.window_channel[1]);
171 }
172 }
173 } else config_show_channel(channel);
174 }
175
176 void config_hide(int number) {
177 /* hide or destroy? if destroy, pointers must be set to NULL */
178 if (number < 2) {
179 if (widgets.window_channel[number] != NULL)
180 gtk_widget_hide(widgets.window_channel[number]);
181 /* widgets.window_channel[number] = NULL; */
182 } else {
183 if (widgets.window_main != NULL)
184 gtk_widget_hide(widgets.window_main);
185 if (widgets.window_channel[0] != NULL)
186 gtk_widget_hide(widgets.window_channel[0]);
187 if (widgets.window_channel[1] != NULL)
188 gtk_widget_hide(widgets.window_channel[1]);
189 widgets.window_main = NULL;
190 widgets.window_channel[0] = NULL;
191 widgets.window_channel[1] = NULL;
192 // THIS SUCKS BEYOND REPAIR!
193 }
194 }
195
196 void config_set_widgets(int number)
197 {
198 if (number < 2) {
199 // set per channel stuff
200 } else {
201 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets.stereo_check), ((conf.stereo>0) ? TRUE : FALSE));
202 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets.debug_check), ((conf.debug>0) ? TRUE : FALSE));
203 }
204 }
205
206 void config_frontend_init(void) {
207 widgets.window_main = NULL;
208 widgets.window_channel[0] = NULL;
209 widgets.window_channel[1] = NULL;
210 }