ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ndk/pen.cpp
Revision: 1.3
Committed: Wed Oct 20 08:33:42 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.2: +11 -10 lines
Log Message:
2 glyphs / map space

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 sf-pippijn 1.3 pen::write (WINDOW *win, wchar_t wc)
40 sf-pippijn 1.1 {
41     #if LIVE
42 sf-pippijn 1.3 waddnwstr (win, &wc, 1);
43 sf-pippijn 1.1 #endif
44     }
45    
46     void
47 sf-pippijn 1.3 pen::write (WINDOW *win, color c, wchar_t wc)
48 sf-pippijn 1.1 {
49     #if LIVE
50 sf-pippijn 1.3 cchar_t ch = { c.attr (), { wc } };
51     wadd_wch (win, &ch);
52 sf-pippijn 1.1 #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 sf-pippijn 1.3 pen::fill (color col)
121 sf-pippijn 1.1 {
122     return_unless (wbkgd (win_, COLOR_PAIR (col.num ())) == OK);
123     }
124    
125     void
126 sf-pippijn 1.3 pen::set_color (color c)
127 sf-pippijn 1.1 {
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 sf-pippijn 1.3 pen::write (wchar_t wc)
186 sf-pippijn 1.1 {
187 sf-pippijn 1.3 write (win_, wc);
188 sf-pippijn 1.1 }
189    
190     void
191 sf-pippijn 1.3 pen::write (color c, wchar_t wc)
192 sf-pippijn 1.1 {
193 sf-pippijn 1.3 write (win_, c, wc);
194 sf-pippijn 1.1 }