ui/colors.cc

Go to the documentation of this file.
00001 // $Id: colors.cc,v 1.3 2008-02-07 23:39:13 rafi Exp $
00002 //
00003 // YAPET -- Yet Another Password Encryption Tool
00004 // Copyright (C) 2008  Rafael Ostertag
00005 //
00006 // This program is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #include "colors.h"
00021 
00022 using namespace YAPETUI;
00023 
00024 bool Colors::initialized = false;
00025 
00026 color Colors::colors[] = { 
00027     // Normal
00028     {1, COLOR_WHITE, COLOR_BLUE, A_NORMAL},
00029     // Message box title
00030     {2, COLOR_CYAN, COLOR_BLACK, A_NORMAL},
00031     // Message box
00032     {3, COLOR_BLACK, COLOR_CYAN, A_NORMAL},
00033     // Input widget no focus
00034     {4, COLOR_BLACK, COLOR_WHITE, A_REVERSE},
00035     // Input widget focus
00036     {5, COLOR_BLACK, COLOR_YELLOW, A_REVERSE},
00037     // Button no focus
00038     {6, COLOR_WHITE, COLOR_BLACK, A_NORMAL},
00039     // Button focus    
00040     {7, COLOR_BLACK, COLOR_GREEN, A_REVERSE},
00041     // List widget
00042     {8, COLOR_WHITE, COLOR_BLUE, A_NORMAL} 
00043 };
00044 
00045 
00046 
00047 void
00048 Colors::initColors() {
00049     if (initialized) return;
00050 
00051     if (has_colors() == FALSE) {
00052     initialized = true;
00053     return;
00054     }
00055 
00056     start_color();
00057     init_pair(colors[DEFAULT].no,
00058           colors[DEFAULT].fg,
00059           colors[DEFAULT].bg);
00060 
00061     init_pair(colors[MESSAGEBOX_TITLE].no,
00062           colors[MESSAGEBOX_TITLE].fg,
00063           colors[MESSAGEBOX_TITLE].bg);
00064 
00065     init_pair(colors[MESSAGEBOX].no,
00066           colors[MESSAGEBOX].fg,
00067           colors[MESSAGEBOX].bg);
00068 
00069     init_pair(colors[INPUTWIDGET_NOFOCUS].no,
00070           colors[INPUTWIDGET_NOFOCUS].fg,
00071           colors[INPUTWIDGET_NOFOCUS].bg);
00072 
00073     init_pair(colors[INPUTWIDGET_FOCUS].no,
00074           colors[INPUTWIDGET_FOCUS].fg,
00075           colors[INPUTWIDGET_FOCUS].bg);
00076 
00077     init_pair(colors[BUTTON_NOFOCUS].no,
00078           colors[BUTTON_NOFOCUS].fg,
00079           colors[BUTTON_NOFOCUS].bg);
00080 
00081     init_pair(colors[BUTTON_FOCUS].no,
00082           colors[BUTTON_FOCUS].fg,
00083           colors[BUTTON_FOCUS].bg);
00084 
00085     init_pair(colors[LISTWIDGET].no,
00086           colors[LISTWIDGET].fg,
00087           colors[LISTWIDGET].bg);
00088     
00089 
00090     initialized = true;
00091 }
00092 
00093 void
00094 Colors::setcolor(WINDOW* w, COLORS c) {
00095     if (has_colors() == TRUE) {
00096     wattron(w, COLOR_PAIR(colors[c].no));
00097     wbkgd(w, ' ' | COLOR_PAIR(colors[c].no));
00098     } else {
00099     wattron(w, colors[c].attr);
00100     wbkgd(w, ' ' | colors[c].attr);
00101     }
00102 }
00103 
00104 short
00105 Colors::getcolor(COLORS c) {
00106     if (has_colors() == TRUE) {
00107     return colors[c].no;
00108     }
00109     return 0;
00110 }
00111 
00112 void
00113 Colors::unsetcolor(WINDOW* w, COLORS c) {
00114     if (has_colors() == TRUE)
00115     wattroff(w, COLOR_PAIR(colors[c].no));
00116     else
00117     wattroff(w, colors[c].attr);
00118 
00119     wbkgd(w, ' ');
00120 }

Generated on Wed Feb 27 16:15:41 2008 for YAPET by  doxygen 1.5.4