ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ndk/pen.cpp
Revision: 1.2
Committed: Tue Oct 19 10:05:57 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.1: +1 -2 lines
Log Message:
don't log waddnwstr errors

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