NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
merged.c File Reference

Merged colours. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "attr.h"
#include "color.h"
#include "curses2.h"
#include "debug.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 (int fg, int 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 46 of file merged.c.

47{
49}
struct AttrColorList MergedColors
Array of user colours.
Definition: merged.c:41
#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 54 of file merged.c.

55{
56 struct AttrColor *ac = NULL;
57 struct AttrColor *tmp = NULL;
58
59 TAILQ_FOREACH_SAFE(ac, &MergedColors, entries, tmp)
60 {
61 TAILQ_REMOVE(&MergedColors, ac, entries);
63 FREE(&ac);
64 }
65}
void curses_color_free(struct CursesColor **ptr)
Free a CursesColor.
Definition: curses.c:121
#define FREE(x)
Definition: memory.h:45
#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:35
struct CursesColor * curses_color
Underlying Curses colour.
Definition: attr.h:36
+ 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 ( int  fg,
int  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 74 of file merged.c.

75{
76 struct AttrColor *ac = NULL;
77 TAILQ_FOREACH(ac, &MergedColors, entries)
78 {
79 if (ac->attrs != attrs)
80 continue;
81
82 bool has_color = (fg != COLOR_DEFAULT) || (bg != COLOR_DEFAULT);
83 struct CursesColor *cc = ac->curses_color;
84
85 // Both have only attributes
86 if (!has_color && !cc)
87 return ac;
88
89 // One has colour, but not the other
90 if ((has_color && !cc) || (!has_color && cc))
91 continue;
92
93 if ((cc->fg == fg) && (cc->bg == bg))
94 return ac;
95 }
96 return NULL;
97}
#define COLOR_DEFAULT
Definition: color.h:104
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
int attrs
Text attributes, e.g. A_BOLD.
Definition: attr.h:37
Colour in the ncurses palette.
Definition: curses2.h:38
uint32_t fg
Foreground colour.
Definition: curses2.h:41
uint32_t bg
Background colour.
Definition: curses2.h:42
+ 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 109 of file merged.c.

111{
112 if (!attr_color_is_set(over))
113 return base;
114 if (!attr_color_is_set(base))
115 return over;
116
117 struct CursesColor *cc_base = base->curses_color;
118 struct CursesColor *cc_over = over->curses_color;
119
120 uint32_t fg = COLOR_DEFAULT;
121 uint32_t bg = COLOR_DEFAULT;
122
123 if (cc_over)
124 {
125 fg = cc_over->fg;
126 bg = cc_over->bg;
127 }
128
129 if (cc_base)
130 {
131 if (fg == COLOR_DEFAULT)
132 fg = cc_base->fg;
133 if (bg == COLOR_DEFAULT)
134 bg = cc_base->bg;
135 }
136
137 int attrs = base->attrs | over->attrs;
138
139 struct AttrColor *ac = merged_colors_find(fg, bg, attrs);
140 if (ac)
141 return ac;
142
143 ac = attr_color_new();
144 ac->curses_color = curses_color_new(fg, bg);
145 ac->attrs = attrs;
146 TAILQ_INSERT_TAIL(&MergedColors, ac, entries);
148
149 return ac;
150}
struct AttrColor * attr_color_new(void)
Create a new AttrColor.
Definition: attr.c:80
bool attr_color_is_set(const struct AttrColor *ac)
Is the object coloured?
Definition: attr.c:160
struct CursesColor * curses_color_new(int fg, int bg)
Create a new CursesColor.
Definition: curses.c:151
void merged_colors_dump(void)
Dump all the Merged colours to the log.
Definition: debug.c:463
static struct AttrColor * merged_colors_find(int fg, int bg, int attrs)
Find a Merged colour.
Definition: merged.c:74
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
+ 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 41 of file merged.c.