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