import psensor trunk from private svn
[psensor.git] / src / ui_color.c
1 /*
2     Copyright (C) 2010-2011 wpitchoune@gmail.com
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17     02110-1301 USA
18 */
19
20 #include <gtk/gtk.h>
21
22 #include "ui_color.h"
23
24 int ui_change_color(const char *title, struct color *col)
25 {
26         GdkColor color;
27         GtkColorSelection *colorsel;
28         int res;
29         GtkColorSelectionDialog *colordlg;
30
31         color.red = col->red;
32         color.green = col->green;
33         color.blue = col->blue;
34
35         colordlg = (GtkColorSelectionDialog *)
36             gtk_color_selection_dialog_new(title);
37
38         colorsel = GTK_COLOR_SELECTION(colordlg->colorsel);
39
40         gtk_color_selection_set_previous_color(colorsel, &color);
41         gtk_color_selection_set_current_color(colorsel, &color);
42
43         res = gtk_dialog_run(GTK_DIALOG(colordlg));
44
45         if (res == GTK_RESPONSE_OK) {
46                 gtk_color_selection_get_current_color(colorsel, &color);
47
48                 color_set(col, color.red, color.green, color.blue);
49         }
50
51         gtk_widget_destroy(GTK_WIDGET(colordlg));
52
53         return res == GTK_RESPONSE_OK;
54 }