1 /*******************************************************************************
2  * Copyright (c) 2013-2021, Andrés Martinelli <andmarti@gmail.com>             *
3  * All rights reserved.                                                        *
4  *                                                                             *
5  * This file is a part of SC-IM                                                *
6  *                                                                             *
7  * SC-IM is a spreadsheet program that is based on SC. The original authors    *
8  * of SC are James Gosling and Mark Weiser, and mods were later added by       *
9  * Chuck Martin.                                                               *
10  *                                                                             *
11  * Redistribution and use in source and binary forms, with or without          *
12  * modification, are permitted provided that the following conditions are met: *
13  * 1. Redistributions of source code must retain the above copyright           *
14  *    notice, this list of conditions and the following disclaimer.            *
15  * 2. Redistributions in binary form must reproduce the above copyright        *
16  *    notice, this list of conditions and the following disclaimer in the      *
17  *    documentation and/or other materials provided with the distribution.     *
18  * 3. All advertising materials mentioning features or use of this software    *
19  *    must display the following acknowledgement:                              *
20  *    This product includes software developed by Andrés Martinelli            *
21  *    <andmarti@gmail.com>.                                                    *
22  * 4. Neither the name of the Andrés Martinelli nor the                        *
23  *   names of other contributors may be used to endorse or promote products    *
24  *   derived from this software without specific prior written permission.     *
25  *                                                                             *
26  * THIS SOFTWARE IS PROVIDED BY ANDRES MARTINELLI ''AS IS'' AND ANY            *
27  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED   *
28  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE      *
29  * DISCLAIMED. IN NO EVENT SHALL ANDRES MARTINELLI BE LIABLE FOR ANY           *
30  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES  *
31  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;*
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
33  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  *
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE       *
35  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.           *
36  *******************************************************************************/
37 
38 /**
39  * \file color.h
40  * \author Andrés Martinelli <andmarti@gmail.com>
41  * \date 2017-07-18
42  * \brief Header file for color.c
43  */
44 
45 #include "macros.h"
46 
47 #include <math.h>
48 #define RGB(r, g, b)    r*999/255, g*999/255, b*999/255
49 
50 #define N_INIT_PAIRS      25
51 
52 struct ucolor {
53     int fg;
54     int bg;
55     int bold;
56     int italic;
57     int dim;
58     int reverse;
59     int standout;
60     int underline;
61     int blink;
62 };
63 
64 struct custom_color {
65     int number; // this is the custom color number. since we max have 24 user custom colors.
66     char * name;
67     int r;
68     int g;
69     int b;
70 
71     /* TODO we actually could store rgb values in just one int
72        int rgb = ((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff);
73        int red = (rgb >> 16) & 0x0ff;
74        int green = (rgb >> 8) & 0x0ff;
75        int blue = (rgb) & 0x0ff;
76      */
77 
78     struct custom_color * p_next;
79 };
80 
81 
82 extern struct ucolor ucolors[N_INIT_PAIRS];
83 
84 struct dictionary * get_d_colors_param();
85 void start_default_ucolors();
86 void color_cell(int r, int c, int rf, int cf, char * detail);
87 void unformat(int r, int c, int rf, int cf);
88 void set_colors_param_dict();
89 void free_colors_param_dict();
90 void chg_color(char * str);
91 int same_ucolor(struct ucolor * u, struct ucolor * v);
92 int redefine_color(char * color, int r, int g, int b);
93 
94 int define_color(char * color, int r, int g, int b);
95 int free_custom_colors();
96 struct custom_color * get_custom_color(char * name);
97 int count_custom_colors();
98 struct custom_color * get_custom_color_by_number(int number);
99