ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/deliantra/dclient/src/backend/ncxx/color.cpp
Revision: 1.3
Committed: Mon Oct 18 14:11:47 2010 UTC (16 years, 1 month ago) by sf-pippijn
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
check and log but do not die when ncurses stuff fails

File Contents

# User Rev Content
1 sf-pippijn 1.1 /* color.cc
2     * This file is part of ncursesxx library
3     * Copyright (c) 2003,2004 by Stanislav Ievlev
4     *
5     * This file is covered by the GNU Library General Public License,
6     * which should be included with libncursesxx as the file COPYING.
7     */
8     #include <ncurses/color.hh>
9    
10     #include <ncurses/assert.hh>
11     #include <ncurses/support.hh>
12    
13     #include <algorithm>
14 sf-pippijn 1.2 #include <map>
15 sf-pippijn 1.1
16     using ncurses::color;
17    
18 sf-pippijn 1.2 static int
19     merge (std::pair<short, short> const &pair)
20     {
21     return pair.first << 16
22     | pair.second
23     ;
24     }
25    
26     static bool
27     operator < (std::pair<short, short> const &a, std::pair<short, short> const &b)
28     {
29     return merge (a) < merge (b);
30     }
31    
32     static std::map<std::pair<short, short>, short> color_pairs;
33    
34     static short
35     make_pair (short fg, short bg)
36     {
37     auto pair = std::make_pair (fg, bg);
38     auto found = color_pairs.find (pair);
39     if (found != color_pairs.end ())
40     return found->second;
41    
42     static short color_counter;
43     color_pairs.insert ({ pair, ++color_counter });
44     return color_counter;
45     }
46 sf-pippijn 1.1
47     color::color ()
48     : attr_ (WA_NORMAL)
49     , num_ (-1)
50     {
51     }
52    
53     color::color (short f, short b, attr_t attr)
54     : attr_ (attr)
55 sf-pippijn 1.2 , num_ (make_pair (f, b))
56 sf-pippijn 1.1 {
57     if (has_colors ())
58 sf-pippijn 1.3 return_unless (init_pair (num_, f, b) == OK);
59 sf-pippijn 1.1 }
60    
61     color::~color ()
62     {
63     }
64    
65     attr_t
66     color::attr () const
67     {
68     return attr_;
69     }
70    
71     short
72     color::num () const
73     {
74     return num_;
75     }