ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ndk/pen.cpp
Revision: 1.1
Committed: Tue Oct 19 09:45:09 2010 UTC (15 years, 11 months ago) by sf-pippijn
Branch: MAIN
Log Message:
- use wchar_t for single characters (glyphs and line drawing)
- merge ncurses and ndk wrappers
- simplify colour caching

File Contents

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