ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ncxx/pen.cpp
Revision: 1.4
Committed: Wed Oct 20 05:09:29 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
State: FILE REMOVED
Log Message:
unused

File Contents

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