1c72fcc34Sopenharmony_ci/*
2c72fcc34Sopenharmony_ci * colors.c - color and attribute definitions
3c72fcc34Sopenharmony_ci * Copyright (c) 1998,1999 Tim Janik
4c72fcc34Sopenharmony_ci *                         Jaroslav Kysela <perex@perex.cz>
5c72fcc34Sopenharmony_ci * Copyright (c) 2009      Clemens Ladisch <clemens@ladisch.de>
6c72fcc34Sopenharmony_ci *
7c72fcc34Sopenharmony_ci * This program is free software: you can redistribute it and/or modify
8c72fcc34Sopenharmony_ci * it under the terms of the GNU General Public License as published by
9c72fcc34Sopenharmony_ci * the Free Software Foundation, either version 2 of the License, or
10c72fcc34Sopenharmony_ci * (at your option) any later version.
11c72fcc34Sopenharmony_ci *
12c72fcc34Sopenharmony_ci * This program is distributed in the hope that it will be useful,
13c72fcc34Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
14c72fcc34Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15c72fcc34Sopenharmony_ci * GNU General Public License for more details.
16c72fcc34Sopenharmony_ci *
17c72fcc34Sopenharmony_ci * You should have received a copy of the GNU General Public License
18c72fcc34Sopenharmony_ci * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19c72fcc34Sopenharmony_ci */
20c72fcc34Sopenharmony_ci
21c72fcc34Sopenharmony_ci#include "aconfig.h"
22c72fcc34Sopenharmony_ci#include CURSESINC
23c72fcc34Sopenharmony_ci#include "colors.h"
24c72fcc34Sopenharmony_ci
25c72fcc34Sopenharmony_cistruct attributes attrs;
26c72fcc34Sopenharmony_cistatic short background_color = -1;
27c72fcc34Sopenharmony_ci
28c72fcc34Sopenharmony_ciint get_color_pair(short fg, short bg)
29c72fcc34Sopenharmony_ci{
30c72fcc34Sopenharmony_ci	static int color_pairs_defined = 0;
31c72fcc34Sopenharmony_ci	short i, pair_fg, pair_bg;
32c72fcc34Sopenharmony_ci
33c72fcc34Sopenharmony_ci	for (i = 1; i <= color_pairs_defined; ++i) {
34c72fcc34Sopenharmony_ci		if (OK == pair_content(i, &pair_fg, &pair_bg))
35c72fcc34Sopenharmony_ci			if (pair_fg == fg && pair_bg == bg)
36c72fcc34Sopenharmony_ci				return COLOR_PAIR(i);
37c72fcc34Sopenharmony_ci	}
38c72fcc34Sopenharmony_ci
39c72fcc34Sopenharmony_ci	if (color_pairs_defined + 1 < COLOR_PAIRS) {
40c72fcc34Sopenharmony_ci		++color_pairs_defined;
41c72fcc34Sopenharmony_ci		init_pair(color_pairs_defined, fg, bg);
42c72fcc34Sopenharmony_ci		return COLOR_PAIR(color_pairs_defined);
43c72fcc34Sopenharmony_ci	}
44c72fcc34Sopenharmony_ci
45c72fcc34Sopenharmony_ci	return 0;
46c72fcc34Sopenharmony_ci}
47c72fcc34Sopenharmony_ci
48c72fcc34Sopenharmony_civoid reinit_colors(short bg)
49c72fcc34Sopenharmony_ci{
50c72fcc34Sopenharmony_ci	if (bg == background_color)
51c72fcc34Sopenharmony_ci		return;
52c72fcc34Sopenharmony_ci	init_pair(1, COLOR_CYAN, bg);
53c72fcc34Sopenharmony_ci	init_pair(2, COLOR_YELLOW, bg);
54c72fcc34Sopenharmony_ci	init_pair(4, COLOR_RED, bg);
55c72fcc34Sopenharmony_ci	init_pair(5, COLOR_WHITE, bg);
56c72fcc34Sopenharmony_ci	background_color = bg;
57c72fcc34Sopenharmony_ci}
58c72fcc34Sopenharmony_ci
59c72fcc34Sopenharmony_civoid init_colors(int use_color)
60c72fcc34Sopenharmony_ci{
61c72fcc34Sopenharmony_ci	if (!!has_colors() == !!use_color) {
62c72fcc34Sopenharmony_ci		start_color();
63c72fcc34Sopenharmony_ci		use_default_colors();
64c72fcc34Sopenharmony_ci
65c72fcc34Sopenharmony_ci		get_color_pair(COLOR_CYAN, background_color); // COLOR_PAIR(1)
66c72fcc34Sopenharmony_ci		get_color_pair(COLOR_YELLOW, background_color);
67c72fcc34Sopenharmony_ci		get_color_pair(COLOR_WHITE, COLOR_GREEN);
68c72fcc34Sopenharmony_ci		get_color_pair(COLOR_RED, background_color);
69c72fcc34Sopenharmony_ci		get_color_pair(COLOR_WHITE, background_color);
70c72fcc34Sopenharmony_ci		get_color_pair(COLOR_WHITE, COLOR_BLUE);
71c72fcc34Sopenharmony_ci		get_color_pair(COLOR_RED, COLOR_BLUE);
72c72fcc34Sopenharmony_ci		get_color_pair(COLOR_GREEN, COLOR_GREEN);
73c72fcc34Sopenharmony_ci		get_color_pair(COLOR_WHITE, COLOR_RED); // COLOR_PAIR(9)
74c72fcc34Sopenharmony_ci#ifdef TRICOLOR_VOLUME_BAR
75c72fcc34Sopenharmony_ci		get_color_pair(COLOR_WHITE, COLOR_WHITE);
76c72fcc34Sopenharmony_ci		get_color_pair(COLOR_RED, COLOR_RED);
77c72fcc34Sopenharmony_ci#endif
78c72fcc34Sopenharmony_ci
79c72fcc34Sopenharmony_ci		attrs = (struct attributes) {
80c72fcc34Sopenharmony_ci			.mixer_frame = COLOR_PAIR(1),
81c72fcc34Sopenharmony_ci			.mixer_text = COLOR_PAIR(1),
82c72fcc34Sopenharmony_ci			.mixer_active = A_BOLD | COLOR_PAIR(2),
83c72fcc34Sopenharmony_ci			.ctl_frame = A_BOLD | COLOR_PAIR(1),
84c72fcc34Sopenharmony_ci			.ctl_mute = COLOR_PAIR(1),
85c72fcc34Sopenharmony_ci			.ctl_nomute = A_BOLD | COLOR_PAIR(3),
86c72fcc34Sopenharmony_ci			.ctl_capture = A_BOLD | COLOR_PAIR(4),
87c72fcc34Sopenharmony_ci			.ctl_nocapture = COLOR_PAIR(5),
88c72fcc34Sopenharmony_ci			.ctl_label = A_BOLD | COLOR_PAIR(6),
89c72fcc34Sopenharmony_ci			.ctl_label_focus = A_BOLD | COLOR_PAIR(7),
90c72fcc34Sopenharmony_ci			.ctl_mark_focus = A_BOLD | COLOR_PAIR(4),
91c72fcc34Sopenharmony_ci			.ctl_bar_lo = A_BOLD | COLOR_PAIR(8),
92c72fcc34Sopenharmony_ci#ifdef TRICOLOR_VOLUME_BAR
93c72fcc34Sopenharmony_ci			.ctl_bar_mi = A_BOLD | COLOR_PAIR(10),
94c72fcc34Sopenharmony_ci			.ctl_bar_hi = A_BOLD | COLOR_PAIR(11),
95c72fcc34Sopenharmony_ci#endif
96c72fcc34Sopenharmony_ci			.ctl_inactive = COLOR_PAIR(5),
97c72fcc34Sopenharmony_ci			.ctl_label_inactive = A_REVERSE | COLOR_PAIR(5),
98c72fcc34Sopenharmony_ci			.errormsg = A_BOLD | COLOR_PAIR(9),
99c72fcc34Sopenharmony_ci			.infomsg = A_BOLD | COLOR_PAIR(6),
100c72fcc34Sopenharmony_ci			.textbox = A_BOLD | COLOR_PAIR(6),
101c72fcc34Sopenharmony_ci			.textfield = A_REVERSE | COLOR_PAIR(5),
102c72fcc34Sopenharmony_ci			.menu = A_BOLD | COLOR_PAIR(6),
103c72fcc34Sopenharmony_ci			.menu_selected = A_REVERSE | COLOR_PAIR(6)
104c72fcc34Sopenharmony_ci		};
105c72fcc34Sopenharmony_ci	} else {
106c72fcc34Sopenharmony_ci		attrs = (struct attributes) {
107c72fcc34Sopenharmony_ci			.mixer_frame = A_NORMAL,
108c72fcc34Sopenharmony_ci			.mixer_text = A_NORMAL,
109c72fcc34Sopenharmony_ci			.mixer_active = A_BOLD,
110c72fcc34Sopenharmony_ci			.ctl_frame = A_BOLD,
111c72fcc34Sopenharmony_ci			.ctl_mute = A_NORMAL,
112c72fcc34Sopenharmony_ci			.ctl_nomute = A_BOLD,
113c72fcc34Sopenharmony_ci			.ctl_capture = A_BOLD,
114c72fcc34Sopenharmony_ci			.ctl_nocapture = A_NORMAL,
115c72fcc34Sopenharmony_ci			.ctl_label = A_REVERSE,
116c72fcc34Sopenharmony_ci			.ctl_label_focus = A_REVERSE | A_BOLD,
117c72fcc34Sopenharmony_ci			.ctl_mark_focus = A_BOLD,
118c72fcc34Sopenharmony_ci			.ctl_bar_lo = A_BOLD,
119c72fcc34Sopenharmony_ci#ifdef TRICOLOR_VOLUME_BAR
120c72fcc34Sopenharmony_ci			.ctl_bar_mi = A_BOLD,
121c72fcc34Sopenharmony_ci			.ctl_bar_hi = A_BOLD,
122c72fcc34Sopenharmony_ci#endif
123c72fcc34Sopenharmony_ci			.ctl_inactive = A_NORMAL,
124c72fcc34Sopenharmony_ci			.ctl_label_inactive = A_REVERSE,
125c72fcc34Sopenharmony_ci			.errormsg = A_STANDOUT,
126c72fcc34Sopenharmony_ci			.infomsg = A_NORMAL,
127c72fcc34Sopenharmony_ci			.textbox = A_NORMAL,
128c72fcc34Sopenharmony_ci			.textfield = A_REVERSE,
129c72fcc34Sopenharmony_ci			.menu = A_NORMAL,
130c72fcc34Sopenharmony_ci			.menu_selected = A_REVERSE,
131c72fcc34Sopenharmony_ci		};
132c72fcc34Sopenharmony_ci	}
133c72fcc34Sopenharmony_ci}
134