1 /*  HomeBank -- Free, easy, personal accounting for everyone.
2  *  Copyright (C) 1995-2021 Maxime DOYEN
3  *
4  *  This file is part of HomeBank.
5  *
6  *  HomeBank is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  HomeBank is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <gtk/gtk.h>
21 
22 #include "gtk-chart-colors.h"
23 
24 
25 #define MYDEBUG 0
26 
27 
28 #if MYDEBUG
29 #define DB(x) (x);
30 #else
31 #define DB(x);
32 #endif
33 
34 
35 
36 char *chart_colors[] =
37 {
38 	"HomeBank",
39 	"Money",
40 	"SAP",
41 	"Quicken",
42 	"Office 2010",
43 	"Office 2013",
44 	"Analytics",
45 	"YNAB",
46 	NULL
47 };
48 
49 
50 struct rgbcol ynab_colors[] =
51 {
52 	{ 238, 118,  96 },
53 	{ 245, 189, 115 },
54 	{ 239, 234, 172 },
55 	{ 143, 186, 209 },
56 	{ 211, 229, 134 },
57 	{ 163, 180, 120 },
58 	{ 167, 209, 195 },
59 	{  51, 177, 191 },
60 	{ 214, 227,  99 },
61 	//{ 246, 166, 209 },	  // added color
62 	{ 131, 131, 131 }	  // others
63 };
64 int ynab_nbcolors = G_N_ELEMENTS(ynab_colors);
65 
66 
67 struct rgbcol money_colors[] =
68 {
69 	{ 255, 193,  96 },
70 	{  92, 131, 180 },
71 	{ 165,  88, 124 },
72 	{ 108, 124, 101 },
73 	{ 230, 121,  99 },
74 	{  91, 160, 154 },
75 	{ 207,  93,  96 },
76 	{  70, 136, 106 },
77 
78 	{ 245, 163,  97 },
79 	{ 158, 153,  88 },
80 	{ 255, 140,  90 },
81 	{ 122, 151, 173 },
82 	{  84, 142, 128 },
83 	{ 185, 201, 149 },
84 	{ 165,  99, 103 },
85 	{  77, 140, 172 },
86 
87 	{ 251, 228, 128 },
88 	{  73,  99, 149 },
89 	{ 192,  80,  77 },
90 	{ 139, 180, 103 },
91 	{ 132, 165, 214 },
92 	{ 221, 216, 115 },
93 	{  77, 103, 137 },
94 	{ 165, 181, 156 }
95 };
96 int money_nbcolors = G_N_ELEMENTS(money_colors);
97 
98 
99 struct rgbcol quicken_colors[] =
100 {
101 	{ 226,  73,  13 },
102 	{ 223, 180,   6 },
103 	{ 124, 179,   0 },
104 	{  44, 108, 182 },
105 	{ 184,  81, 186 },
106 	{ 165, 165, 165 },
107 	{ 122, 122, 122 },
108 	{ 137,  42,  40 },
109 
110 	{  70, 161, 100 },
111 	{ 220, 106,   0 },
112 	{ 113, 113, 113 }	  // others
113 };
114 int quicken_nbcolors = G_N_ELEMENTS(quicken_colors);
115 
116 
117 struct rgbcol analytics_colors[] =
118 {
119 	{   5, 141, 199 },	  //line color
120 	{  80, 180,  50 },
121 	{ 237,  86,  27 },
122 	{ 237, 239,   0 },
123 	{  36, 203, 229 },
124 	{ 100, 229, 114 },
125 	{ 255, 150,  85 },
126 	{ 255, 242,  99 },
127 
128 	{ 106, 249, 196 },
129 	{ 178, 222, 255 },
130 	{ 204, 204, 204 }	  // others
131 };
132 int analytics_nbcolors = G_N_ELEMENTS(analytics_colors);
133 
134 
135 struct rgbcol office2010_colors[] =
136 {
137 	{  60, 100, 149 },
138 	{ 150,  60,  59 },
139 	{ 120, 147,  68 },
140 	{  99,  75, 123 },
141 	{  61, 133, 157 },
142 	{ 196, 115,  49 },
143 
144 	{  73, 120, 176 },
145 	{ 179,  74,  71 },
146 	{ 144, 178,  84 },
147 	{ 117,  93, 153 },
148 	{  73, 161, 185 },
149 	{ 232, 140,  65 },
150 
151 	{ 126, 155, 199 },
152 	{ 202, 126, 126 },
153 	{ 174, 197, 129 },
154 	{ 156, 137, 182 },
155 	{ 123, 185, 206 },
156 	{ 248, 170, 121 }
157 };
158 int office2010_nbcolors = G_N_ELEMENTS(office2010_colors);
159 
160 
161 struct rgbcol office2013_colors[] =
162 {
163 	{  91, 155, 213  },
164 	{ 237, 125,  49  },
165 	{ 165, 165, 165  },
166 	{ 255, 192,   0  },
167 	{  68, 114, 196  },
168 	{ 112, 173,  71  },
169 
170 	{  37,  94, 145  },
171 	{ 158,  72,  14  },
172 	{  99,  99,  99  },
173 	{ 153, 115,   0  },
174 	{  38,  68, 120  },
175 	{  67, 104,  43  },
176 
177 	{ 124, 175, 221  },
178 	{ 241, 151,  90  },
179 	{ 183, 183, 183  },
180 	{ 255, 205,  51  },
181 	{ 105, 142, 208  },
182 	{ 140, 193, 104  }
183 };
184 int office2013_nbcolors = G_N_ELEMENTS(office2013_colors);
185 
186 struct rgbcol sap_colors[] =
187 {
188 	{ 107, 148, 181  },
189 	{ 239, 205, 120  },
190 	{ 160, 117, 146  },
191 	{ 107, 181, 144  },
192 	{ 237, 164, 112  },
193 	{ 107, 106, 161  },
194 	{ 183, 213, 104  },
195 	{ 214, 128, 118  },
196 
197 	{ 135, 115, 161  },
198 	{ 218, 217,  86  },
199 	{ 207, 111, 122  },
200 	{  85, 168, 161  },
201 	{ 253, 213,  65  },
202 	{ 146,  98, 148  },
203 	{ 115, 192,  59  },
204 	{ 205,  81,  96  },
205 
206 	{  53, 180, 201  },
207 	{ 248, 175, 103  },
208 	{ 186,  97, 125  },
209 	{ 117, 202, 249  },
210 	{ 244, 131,  35  },
211 	{ 178,  45, 110  },
212 	{  87, 229, 151  },
213 	{ 204, 171,  68  },
214 
215 	{ 172, 110, 145  },
216 	{  61, 132, 137  },
217 	{ 224, 117,  79  },
218 	{ 117,  84, 148  },
219 	{ 155, 206, 158  },
220 	{ 255, 133, 100  },
221 	{  60,  98, 153  },
222 	{ 128, 197, 122  }
223 };
224 int sap_nbcolors = G_N_ELEMENTS(sap_colors);
225 
226 struct rgbcol homebank_colors[] =
227 {
228 	{  72, 118, 176  },
229 	{ 180, 198, 230  },
230 	{ 227, 126,  35  },
231 	{ 238, 186, 123  },
232 	{  97, 158,  58  },
233 	{ 175, 222, 142  },
234 	{ 184,  43,  44  },
235 	{ 231, 151, 149  },
236 	{ 136, 103, 185  },
237 	{ 190, 174, 210  },
238 	{ 127,  87,  77  },
239 	{ 184, 155, 147  },
240 	{ 202, 118, 190  },
241 	{ 230, 181, 208  },
242 	{ 126, 126, 126  },
243 	{ 198, 198, 198  },
244 	{ 187, 188,  56  },
245 	{ 218, 218, 144  },
246 	{ 109, 189, 205  },
247 	{ 176, 217, 228  },
248 
249 	{ 237, 212,   0  },
250 	{ 255, 239, 101  },
251 	{ 207,  93,  96  },
252 	{ 234, 186, 187  },
253 	{ 193, 124,  17  },
254 	{ 240, 181,  90  },
255 	{ 186, 189, 182  },
256 	{ 225, 227, 223  },
257 	{ 115, 210,  22  },
258 	{ 175, 240, 112  },
259 	{ 255, 140,  90  },
260 	{ 255, 191, 165  }
261 
262 };
263 int homebank_nbcolors = G_N_ELEMENTS(homebank_colors);
264 
265 
266 
267 struct rgbcol global_colors[] =
268 {
269 	{  0,   0,   0},	// black
270 	{255, 255, 255},	// white
271 	{239, 239, 239},	// grey1	THTEXT 0.05
272 	{ 68,  68,  68},	// text		THTEXT 0.78
273 	{ 51,  51,  51},	// xyline   THTEXT 0.8
274 
275 
276 /*	{  255,   0,   0},	// fake
277 	{  255,   255,   0},	// fake
278 	{  255,   0,   255},	// fake
279 	{  0,   255,   0},	// fake
280 	{  0,   0,   255},	// fake
281 */
282 
283 
284 	{255, 255, 255},	// theme base (bg)
285 	{ 46,  52,  54},	// theme fg
286 };
287 
288 
289 
290 /*
291 struct rgbcol global_colors[] =
292 {
293 	{  0,   0,   0},	// black
294 	{255, 255, 255},	// white
295 	{238, 238, 238},	// #top/bottom lines
296 	{204, 204, 204},	// #dotted lines
297 	{102, 102, 102},	// #x-axis, scale text
298 	{153, 153, 153},	// # ??
299 	{  0, 119, 204},	// #line color
300 
301 	//new
302 	{239, 239, 239},	// intermediate lines
303 	{ 68,  68,  68},	// text
304 	{ 51,  51,  51},	// x/y axis
305 
306 
307 };*/
308 
309 
chart_color_global_default(void)310 void chart_color_global_default(void)
311 {
312 struct rgbcol *tcol;
313 
314 	// set base color (adwaita)
315 	tcol = &global_colors[THBASE];
316 	tcol->r = 255;
317 	tcol->g = 255;
318 	tcol->b = 255;
319 
320 	// set text(bg) color (adwaita)
321 	tcol = &global_colors[THTEXT];
322 	tcol->r = 46;
323 	tcol->g = 52;
324 	tcol->b = 54;
325 }
326 
327 
cairo_user_set_rgbcol(cairo_t * cr,struct rgbcol * col)328 void cairo_user_set_rgbcol(cairo_t *cr, struct rgbcol *col)
329 {
330 	cairo_set_source_rgb(cr, COLTOCAIRO(col->r), COLTOCAIRO(col->g), COLTOCAIRO(col->b));
331 }
332 
333 
cairo_user_set_rgbacol(cairo_t * cr,struct rgbcol * col,double alpha)334 void cairo_user_set_rgbacol(cairo_t *cr, struct rgbcol *col, double alpha)
335 {
336 	cairo_set_source_rgba(cr, COLTOCAIRO(col->r), COLTOCAIRO(col->g), COLTOCAIRO(col->b), alpha);
337 }
338 
339 
cairo_user_set_rgbcol_over(cairo_t * cr,struct rgbcol * col,gboolean over)340 void cairo_user_set_rgbcol_over(cairo_t *cr, struct rgbcol *col, gboolean over)
341 {
342 	if( over )
343 		cairo_set_source_rgb(cr, COLTOCAIROOVER(col->r), COLTOCAIROOVER(col->g), COLTOCAIROOVER(col->b));
344 	else
345 		cairo_set_source_rgb(cr, COLTOCAIRO(col->r), COLTOCAIRO(col->g), COLTOCAIRO(col->b));
346 }
347 
348 
colorscheme_init(GtkColorScheme * scheme,gint index)349 void colorscheme_init(GtkColorScheme *scheme, gint index)
350 {
351 
352 	DB( g_print("\n[chart] scheme init\n") );
353 
354 	scheme->cs_blue = 0;
355 
356 	switch(index)
357 	{
358 		default:
359 		case CHART_COLMAP_HOMEBANK:
360 			scheme->colors = homebank_colors;
361 			scheme->nb_cols = homebank_nbcolors;
362 			scheme->cs_green = 4;
363 			scheme->cs_red = 6;
364 			scheme->cs_orange = 2;
365 			break;
366 		case CHART_COLMAP_MSMONEY:
367 			scheme->colors = money_colors;
368 			scheme->nb_cols = money_nbcolors;
369 			scheme->cs_blue = 17;
370 			scheme->cs_green = 19;
371 			scheme->cs_red = 18;
372 			scheme->cs_orange = 8;
373 			break;
374 		case CHART_COLMAP_QUICKEN:
375 			scheme->colors = quicken_colors;
376 			scheme->nb_cols = quicken_nbcolors;
377 			scheme->cs_blue = 3;
378 			scheme->cs_green = 2;
379 			scheme->cs_red = 0;
380 			scheme->cs_orange = 9;
381 			break;
382 		case CHART_COLMAP_ANALYTICS:
383 			scheme->colors = analytics_colors;
384 			scheme->nb_cols = analytics_nbcolors;
385 			scheme->cs_green = 1;
386 			scheme->cs_red = 2;
387 			scheme->cs_orange = 6;
388 			break;
389 		case CHART_COLMAP_OFFICE2010:
390 			scheme->colors = office2010_colors;
391 			scheme->nb_cols = office2010_nbcolors;
392 			scheme->cs_green = 2;
393 			scheme->cs_red = 1;
394 			scheme->cs_orange = 5;
395 			break;
396 		case CHART_COLMAP_OFFICE2013:
397 			scheme->colors = office2013_colors;
398 			scheme->nb_cols = office2013_nbcolors;
399 			scheme->cs_green = 5;
400 			scheme->cs_red = 1;
401 			scheme->cs_orange = 1;
402 			break;
403 		case CHART_COLMAP_SAP:
404 			scheme->colors = sap_colors;
405 			scheme->nb_cols = sap_nbcolors;
406 			scheme->cs_green = 14;
407 			scheme->cs_red = 15;
408 			scheme->cs_orange = 20;
409 			break;
410 		case CHART_COLMAP_YNAB:
411 			scheme->colors = ynab_colors;
412 			scheme->nb_cols = ynab_nbcolors;
413 			scheme->cs_blue = 3;
414 			scheme->cs_green = 5;
415 			scheme->cs_red = 0;
416 			scheme->cs_orange = 1;
417 			break;
418 	}
419 
420 
421 }
422 
423