ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ndk/label.cpp
Revision: 1.2
Committed: Mon Oct 18 14:11:48 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.1: +3 -1 lines
Log Message:
check and log but do not die when ncurses stuff fails

File Contents

# User Rev Content
1 sf-pippijn 1.1 /* label.cc
2     * This file is part of NDK++ library
3     * Copyright (c) 2003 by Stanislav Ievlev
4     *
5     * This file is covered by the GNU Library General Public License,
6     * which should be included with libndk++ as the file COPYING.
7     */
8     #include <ndk++/label.hh>
9     #include <ndk++/palette.hh>
10    
11 sf-pippijn 1.2 #include <ncurses/assert.hh>
12    
13 sf-pippijn 1.1 using namespace ndk;
14    
15     label::label (const std::string &str, ndk::panel *parent)
16     : ndk::panel (parent)
17     , text_ (str)
18     {
19     if (!str.empty ())
20     panel::resize (str.length (), 1);
21     events ()->set_accept (false); /* this widget doesn't accept focus */
22     }
23    
24     void
25     label::set_text (const std::string &str)
26     {
27     text_ = str;
28     }
29    
30     const std::string &
31     label::text () const
32     {
33     return text_;
34     }
35    
36     void
37     label::draw ()
38     {
39     draw (this->text_, 0); /* simple drawing of the text */
40     }
41    
42     void
43     label::draw (const std::string &str, std::string::size_type begin)
44     {
45     ncurses::pen p (*this);
46    
47     set_color (p);
48 sf-pippijn 1.2 return_unless (p.move (0, 0));
49 sf-pippijn 1.1 std::string out (str.substr (begin, this->width ()));
50     if (int (out.length ()) < this->width ())
51     out.append (this->width () - out.length (), ' ');
52     p.write (out);
53     }
54    
55     void
56     label::set_color (ncurses::pen &p)
57     {
58     p.set_color (palette::instance ()[colors::label]);
59     }