File: colors.c

package info (click to toggle)
melon 1.4-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 956 kB
  • ctags: 158
  • sloc: ansic: 2,427; makefile: 91; sh: 58
file content (144 lines) | stat: -rw-r--r-- 4,098 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* colors.c -- color setting
 *
 * Copyright(C) 2001-2002 Elisa Manara <e@entropika.net>
 * This code is released under the GPL License version 2 */


#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
#include "melon.h"

GtkWidget *colorseldlg = NULL;
GdkColor gdk_color;
	char msg[256];

void set_color (GtkWidget *widget, GtkColorSelection *colorsel);
gint update_color (GtkWidget *widget, gpointer data);

gint color_selector (GtkWidget *widget, gpointer color_data)
{
	GtkWidget *colorsel;
	char title[256];
	gdouble old_col[3];
	GdkColor old_color;

	/* gtk default colors */
	if (strcmp(color_data, "gdef") == 0) {
		strncpy(cfg_data.color_style, "gtk_default", 16);
		strncpy(msg, " Colors updated to Gtk Default ", 256);
		set_style();
		config_update();
		dialog_message(msg);
		return 1;
	/* melon default colors */
	} else if (strcmp(color_data, "mdef") == 0) {
		strncpy(cfg_data.color_style, "melon_default", 16);
		strncpy(msg, " Colors updated to Melon Default ", 256);
		set_melon_def_colors();
		set_style();
		config_update();
		dialog_message(msg);
		return 1;

	} else if (strcmp(color_data, "bg") == 0) {
		strncpy(title, "Select background color", 256);
		strncpy(msg, " Background color updated ", 256);
		old_color = cfg_data.bgcolor;
	} else if (strcmp(color_data, "fg") == 0) {
		strncpy(title, "Select foreground color", 256);
		strncpy(msg, " Foreground color updated ", 256);
		old_color = cfg_data.fgcolor;
	} else if (strcmp(color_data, "abg") == 0) {
		strncpy(title, "Select active background color", 256);
		strncpy(msg, " Active background color updated ", 256);
		old_color = cfg_data.abgcolor;
	} else if (strcmp(color_data, "afg") == 0) {
		strncpy(title, "Select active foreground color", 256);
		strncpy(msg, " Active foreground color updated ", 256);
		old_color = cfg_data.afgcolor;
	}

	old_col[0] = old_color.red / 65535.0;
	old_col[1] = old_color.green / 65535.0;
	old_col[2] = old_color.blue / 65535.0;

	colorseldlg = gtk_color_selection_dialog_new(title);
	gtk_widget_hide ( GTK_COLOR_SELECTION_DIALOG(colorseldlg)->help_button );

	colorsel = GTK_COLOR_SELECTION_DIALOG(colorseldlg)->colorsel;
	gtk_color_selection_set_update_policy(GTK_COLOR_SELECTION( colorsel ), 
		GTK_UPDATE_DISCONTINUOUS);
	gtk_color_selection_set_color(GTK_COLOR_SELECTION( colorsel ), old_col);

	gtk_signal_connect(GTK_OBJECT(colorsel), "color_changed",
		(GtkSignalFunc)set_color, (gpointer)colorsel);

	gtk_signal_connect 
		(GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG(colorseldlg)->ok_button), "clicked",
		GTK_SIGNAL_FUNC(update_color), color_data);

	gtk_signal_connect_object 
		(GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG(colorseldlg)->ok_button), "clicked",
		GTK_SIGNAL_FUNC(gtk_widget_destroy),
		GTK_OBJECT (colorseldlg));

	gtk_signal_connect_object 
		(GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG(colorseldlg)->cancel_button), "clicked",
		GTK_SIGNAL_FUNC(gtk_widget_destroy),
		GTK_OBJECT (colorseldlg));

	gtk_widget_show(colorseldlg);

	return 1;
}

void set_color ( GtkWidget *widget, GtkColorSelection *colorsel )
{
	gdouble color[3];

	/* get selected color */
	gtk_color_selection_get_color (colorsel, color);

	gdk_color.red = (guint16)(color[0]*65535.0);
	gdk_color.green = (guint16)(color[1]*65535.0);
	gdk_color.blue = (guint16)(color[2]*65535.0);
}

gint update_color (GtkWidget *widget, gpointer data)
{
	if (strcmp(data, "bg") == 0) {
		cfg_data.bgcolor = gdk_color;
	} else if (strcmp(data, "fg") == 0) {
		cfg_data.fgcolor = gdk_color;
	} else if (strcmp(data, "abg") == 0) {
		cfg_data.abgcolor = gdk_color;
	} else if (strcmp(data, "afg") == 0) {
		cfg_data.afgcolor = gdk_color;
	}

	strncpy(cfg_data.color_style, "custom", 16);
	set_style();
	config_update();
	dialog_message(msg);

	return 1;
}

void set_melon_def_colors (void)
{
	GdkColor def_colors[] =
	{
		{0, 0x30b9, 0x6c9a, 0x2375},
		{0, 0xffff, 0xf89d, 0x678a},
		{0, 0x22a6, 0x85d0, 0x21b5},
		{0, 0xcba2, 0x2fe9, 0x2fe9},
	};

	cfg_data.bgcolor = def_colors[0];
	cfg_data.fgcolor = def_colors[1];
	cfg_data.abgcolor = def_colors[2];
	cfg_data.afgcolor = def_colors[3];
	return;
}