• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ui/colors.cc

Go to the documentation of this file.
00001 // $Id: colors.cc 3342 2010-09-17 18:32:00Z java $
00002 //
00003 // Copyright (C) 2008-2010  Rafael Ostertag
00004 //
00005 // This file is part of YAPET.
00006 //
00007 // YAPET is free software: you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the Free Software
00009 // Foundation, either version 3 of the License, or (at your option) any later
00010 // version.
00011 //
00012 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015 // details.
00016 //
00017 // You should have received a copy of the GNU General Public License along with
00018 // YAPET.  If not, see <http://www.gnu.org/licenses/>.
00019 //
00020 
00021 #ifdef HAVE_CONFIG_H
00022 # include "config.h"
00023 #endif
00024 
00025 #ifdef HAVE_ASSERT_H
00026 # include <assert.h>
00027 #endif
00028 
00029 #include "colors.h"
00030 
00031 using namespace YAPET::UI;
00032 
00033 bool Colors::initialized = false;
00034 
00035 #ifndef _GIRLYCOLORS
00036 color Colors::colors[] = {
00037     // Normal
00038     {1, COLOR_WHITE, COLOR_BLUE, A_NORMAL},
00039     // Message box title
00040     {2, COLOR_CYAN, COLOR_BLACK, A_NORMAL},
00041     // Message box
00042     {3, COLOR_BLACK, COLOR_CYAN, A_NORMAL},
00043     // Input widget no focus
00044     {4, COLOR_BLACK, COLOR_WHITE, A_REVERSE},
00045     // Input widget focus
00046     {5, COLOR_BLACK, COLOR_YELLOW, A_REVERSE},
00047     // Button no focus
00048     {6, COLOR_WHITE, COLOR_BLACK, A_NORMAL},
00049     // Button focus
00050     {7, COLOR_BLACK, COLOR_GREEN, A_REVERSE},
00051     // List widget
00052     {8, COLOR_WHITE, COLOR_BLUE, A_NORMAL},
00053     // Check Box Group
00054     {9, COLOR_BLACK, COLOR_CYAN, A_NORMAL},
00055     // Check Box Group Title
00056     {10, COLOR_CYAN, COLOR_BLACK, A_NORMAL},
00057     // The marker of the end
00058     {0, 0, 0, 0}
00059 };
00060 #else
00061 //
00062 // Don't ask, my wife insisted... ;)
00063 //
00064 color Colors::colors[] = {
00065     // Normal
00066     {1, COLOR_BLUE, COLOR_CYAN, A_NORMAL},
00067     // Message box title
00068     {2, COLOR_CYAN, COLOR_BLACK, A_NORMAL},
00069     // Message box
00070     {3, COLOR_BLACK, COLOR_CYAN, A_NORMAL},
00071     // Input widget no focus
00072     {4, COLOR_BLACK, COLOR_WHITE, A_REVERSE},
00073     // Input widget focus
00074     {5, COLOR_WHITE, COLOR_MAGENTA, A_REVERSE},
00075     // Button no focus
00076     {6, COLOR_BLUE, COLOR_CYAN, A_NORMAL},
00077     // Button focus
00078     {7, COLOR_CYAN, COLOR_MAGENTA, A_REVERSE},
00079     // List widget
00080     {8, COLOR_BLUE, COLOR_CYAN, A_NORMAL},
00081     // Check Box Group
00082     {9, COLOR_BLACK, COLOR_CYAN, A_NORMAL},
00083     // Check Box Group Title
00084     {10, COLOR_CYAN, COLOR_BLACK, A_NORMAL},
00085     // The marker of the end
00086     {0, 0, 0, 0}
00087 };
00088 #endif
00089 
00090 
00091 void
00092 Colors::initColors() {
00093     if (initialized) return;
00094 
00095     if (has_colors() == FALSE) {
00096         initialized = true;
00097         return;
00098     }
00099 
00100     start_color();
00101     assert (colors[CHECKBOXGROUP_TITLE+1].no == 0);
00102 
00103     for (int i = 0; colors[i].no != 0; i++)
00104         init_pair (colors[i].no,
00105                    colors[i].fg,
00106                    colors[i].bg);
00107 
00108     initialized = true;
00109 }
00110 
00111 void
00112 Colors::setcolor (WINDOW* w, COLORS c) {
00113     if (has_colors() == TRUE) {
00114         wattron (w, COLOR_PAIR (colors[c].no) );
00115         wbkgd (w, ' ' | COLOR_PAIR (colors[c].no) );
00116     } else {
00117         wattron (w, colors[c].attr);
00118         wbkgd (w, ' ' | colors[c].attr);
00119     }
00120 }
00121 
00122 short
00123 Colors::getcolor (COLORS c) {
00124     if (has_colors() == TRUE) {
00125         return colors[c].no;
00126     }
00127 
00128     return 0;
00129 }
00130 
00131 void
00132 Colors::unsetcolor (WINDOW* w, COLORS c) {
00133     if (has_colors() == TRUE)
00134         wattroff (w, COLOR_PAIR (colors[c].no) );
00135     else
00136         wattroff (w, colors[c].attr);
00137 
00138     wbkgd (w, ' ');
00139 }

Generated on Sun Sep 19 2010 15:37:13 for YAPET by  doxygen 1.7.1