NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
merged.c File Reference

Merged colours. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "mutt/lib.h"
#include "attr.h"
#include "color.h"
#include "curses2.h"
+ Include dependency graph for merged.c:

Go to the source code of this file.

Functions

void merged_colors_init (void)
 Initialise the Merged colours.
 
void merged_colors_cleanup (void)
 Free the list of Merged colours.
 
static struct AttrColormerged_colors_find (color_t fg, color_t bg, int attrs)
 Find a Merged colour.
 
const struct AttrColormerged_color_overlay (const struct AttrColor *base, const struct AttrColor *over)
 Combine two colours.
 

Variables

struct AttrColorList MergedColors
 Array of user colours.
 

Detailed Description

Merged colours.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file merged.c.

Function Documentation

◆ merged_colors_init()

void merged_colors_init ( void  )

Initialise the Merged colours.

Definition at line 44 of file merged.c.

45{
47}
struct AttrColorList MergedColors
Array of user colours.
Definition: merged.c:39
#define TAILQ_INIT(head)
Definition: queue.h:765
+ Here is the caller graph for this function:

◆ merged_colors_cleanup()

void merged_colors_cleanup ( void  )

Free the list of Merged colours.

Definition at line 52 of file merged.c.

53{
54 struct AttrColor *ac = NULL;
55 struct AttrColor *tmp = NULL;
56
57 TAILQ_FOREACH_SAFE(ac, &MergedColors, entries, tmp)
58 {
59 TAILQ_REMOVE(&MergedColors, ac, entries);
61 FREE(&ac);
62 }
63}
void curses_color_free(struct CursesColor **ptr)
Free a CursesColor.
Definition: curses.c:120
#define FREE(x)
Definition: memory.h:55
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
A curses colour and its attributes.
Definition: attr.h:66
struct CursesColor * curses_color
Underlying Curses colour.
Definition: attr.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ merged_colors_find()

static struct AttrColor * merged_colors_find ( color_t  fg,
color_t  bg,
int  attrs 
)
static

Find a Merged colour.

Parameters
fgForeground colour
bgBackground colour
attrsAttributes, e.g. A_UNDERLINE
Return values
ptrMatching Merged colour

Definition at line 72 of file merged.c.

73{
74 struct AttrColor *ac = NULL;
75 TAILQ_FOREACH(ac, &MergedColors, entries)
76 {
77 if (ac->attrs != attrs)
78 continue;
79
80 bool has_color = (fg != COLOR_DEFAULT) || (bg != COLOR_DEFAULT);
81 struct CursesColor *cc = ac->curses_color;
82
83 // Both have only attributes
84 if (!has_color && !cc)
85 return ac;
86
87 // One has colour, but not the other
88 if ((has_color && !cc) || (!has_color && cc))
89 continue;
90
91 if ((cc->fg == fg) && (cc->bg == bg))
92 return ac;
93 }
94 return NULL;
95}
#define COLOR_DEFAULT
Definition: color.h:100
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct ColorElement bg
Background colour.
Definition: attr.h:68
struct ColorElement fg
Foreground colour.
Definition: attr.h:67
int attrs
Text attributes, e.g. A_BOLD.
Definition: attr.h:69
Colour in the ncurses palette.
Definition: curses2.h:41
color_t fg
Foreground colour.
Definition: curses2.h:42
color_t bg
Background colour.
Definition: curses2.h:43
+ Here is the caller graph for this function:

◆ merged_color_overlay()

const struct AttrColor * merged_color_overlay ( const struct AttrColor base,
const struct AttrColor over 
)

Combine two colours.

Parameters
baseBase colour
overOverlay colour
Return values
ptrMerged colour

If either the foreground or background of the overlay is 'default', then the base colour will show through. The attributes of both base and overlay will be OR'd together.

Definition at line 107 of file merged.c.

109{
110 if (!attr_color_is_set(over))
111 return base;
112 if (!attr_color_is_set(base))
113 return over;
114
115 struct CursesColor *cc_base = base->curses_color;
116 struct CursesColor *cc_over = over->curses_color;
117
120
121 if (cc_over)
122 {
123 fg = cc_over->fg;
124 bg = cc_over->bg;
125 }
126
127 if (cc_base)
128 {
129 if (fg == COLOR_DEFAULT)
130 fg = cc_base->fg;
131 if (bg == COLOR_DEFAULT)
132 bg = cc_base->bg;
133 }
134
135 int attrs = base->attrs | over->attrs;
136
137 struct AttrColor *ac = merged_colors_find(fg, bg, attrs);
138 if (ac)
139 return ac;
140
141 ac = attr_color_new();
143 ac->attrs = attrs;
144 ac->fg = (base->fg.color == COLOR_DEFAULT) ? over->fg : base->fg;
145 ac->bg = (base->bg.color == COLOR_DEFAULT) ? over->bg : base->bg;
146 TAILQ_INSERT_TAIL(&MergedColors, ac, entries);
147
148 return ac;
149}
struct AttrColor * attr_color_new(void)
Create a new AttrColor.
Definition: attr.c:90
bool attr_color_is_set(const struct AttrColor *ac)
Is the object coloured?
Definition: attr.c:179
int32_t color_t
Type for 24-bit colour value.
Definition: curses2.h:31
struct CursesColor * curses_color_new(color_t fg, color_t bg)
Create a new CursesColor.
Definition: curses.c:151
static struct AttrColor * merged_colors_find(color_t fg, color_t bg, int attrs)
Find a Merged colour.
Definition: merged.c:72
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
color_t color
Colour.
Definition: attr.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MergedColors

struct AttrColorList MergedColors

Array of user colours.

Definition at line 39 of file merged.c.