ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ncxx/pen.cpp
Revision: 1.1
Committed: Sun Oct 17 08:15:07 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Log Message:
initial import

File Contents

# User Rev Content
1 sf-pippijn 1.1 #include <ncurses/pen.hh>
2    
3     #include <ncurses/assert.hh>
4     #include <ncurses/color.hh>
5     #include <ncurses/pad.hh>
6     #include <ncurses/window.hh>
7    
8    
9     static bool
10     is_bold (WINDOW *win)
11     {
12     short pair;
13     attr_t attrs;
14    
15     wattr_get (win, &attrs, &pair, NULL);
16    
17     return attrs & WA_BOLD;
18     }
19    
20    
21     using ncurses::pen;
22    
23     void
24     pen::write (WINDOW *win, char const *str, int len)
25     {
26     waddnstr (win, str, len);
27     }
28    
29     void
30     pen::write (WINDOW *win, std::string const &str)
31     {
32     write (win, str.data (), str.length ());
33     }
34    
35     void
36     pen::write (WINDOW *win, char const ch)
37     {
38     NCURSES_ASSERT (waddch (win, ch));
39     }
40    
41     std::string const &pen::ltitle (bool bold) { static std::string const s[2] = { "┤", "╣" }; return s[bold]; }
42     std::string const &pen::rtitle (bool bold) { static std::string const s[2] = { "├", "╠" }; return s[bold]; }
43     std::string const &pen::ulcorner (bool bold) { static std::string const s[2] = { "┌", "╔" }; return s[bold]; }
44     std::string const &pen::llcorner (bool bold) { static std::string const s[2] = { "└", "╚" }; return s[bold]; }
45     std::string const &pen::urcorner (bool bold) { static std::string const s[2] = { "┐", "╗" }; return s[bold]; }
46     std::string const &pen::lrcorner (bool bold) { static std::string const s[2] = { "┘", "╝" }; return s[bold]; }
47     std::string const &pen::h_line (bool bold) { static std::string const s[2] = { "─", "═" }; return s[bold]; }
48     std::string const &pen::v_line (bool bold) { static std::string const s[2] = { "│", "║" }; return s[bold]; }
49    
50     pen::pen (window &win)
51     : win_ (win.win ())
52     {
53     }
54    
55     pen::pen (pad &pad)
56     : win_ (pad.win ())
57     {
58     }
59    
60     /**< move pen to the new position */
61     void
62     pen::move (int x, int y)
63     {
64     NCURSES_ASSERT (wmove (win_, y, x));
65     }
66    
67     void
68     pen::commit ()
69     {
70     NCURSES_ASSERT (wnoutrefresh (win_));
71     }
72    
73     int
74     pen::x () const
75     {
76     return getcurx (win_);
77     }
78    
79     int
80     pen::y () const
81     {
82     return getcury (win_);
83     }
84    
85     void
86     pen::clear ()
87     {
88     NCURSES_ASSERT (werase (win_));
89     }
90    
91     void
92     pen::fill (color const &col)
93     {
94     NCURSES_ASSERT (wbkgd (win_, COLOR_PAIR (col.num ())));
95     }
96    
97     void
98     pen::set_color (color const &c)
99     {
100     /* what should I use here: wattrset or wattr_set */
101     NCURSES_ASSERT (wattr_set (win_, c.attr (), c.num (), 0));
102     }
103    
104     void
105     pen::frame ()
106     {
107     move (0, 0);
108    
109     bool const bold = is_bold (win_);
110    
111     int maxx, maxy;
112     getmaxyx (win_, maxy, maxx);
113    
114     write (ulcorner (bold));
115     for (int i = 1; i < maxx - 1; i++)
116     write (h_line (bold));
117     write (urcorner (bold));
118    
119     for (int i = 1; i < maxy; i++)
120     {
121     write (v_line (bold));
122     move (0, i);
123     }
124    
125     write (llcorner (bold));
126     for (int i = 1; i < maxx - 1; i++)
127     write (h_line (bold));
128     write (lrcorner (bold));
129    
130     for (int i = 1; i < maxy - 1; i++)
131     {
132     move (maxx - 1, i);
133     write (v_line (bold));
134     }
135     }
136    
137     void
138     pen::title (std::string const &title)
139     {
140     bool const bold = is_bold (win_);
141    
142     move (2, 0);
143     write (ltitle (bold));
144     write (title);
145     write (rtitle (bold));
146     }
147    
148     void
149     pen::write (std::string const &str)
150     {
151     write (win_, str);
152     }
153    
154     void
155     pen::write (char const ch)
156     {
157     write (win_, ch);
158     }