ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ndk/label.cpp
Revision: 1.1
Committed: Sun Oct 17 08:15:09 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Log Message:
initial import

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     using namespace ndk;
12    
13     label::label (const std::string &str, ndk::panel *parent)
14     : ndk::panel (parent)
15     , text_ (str)
16     {
17     if (!str.empty ())
18     panel::resize (str.length (), 1);
19     events ()->set_accept (false); /* this widget doesn't accept focus */
20     }
21    
22     void
23     label::set_text (const std::string &str)
24     {
25     text_ = str;
26     }
27    
28     const std::string &
29     label::text () const
30     {
31     return text_;
32     }
33    
34     void
35     label::draw ()
36     {
37     draw (this->text_, 0); /* simple drawing of the text */
38     }
39    
40     void
41     label::draw (const std::string &str, std::string::size_type begin)
42     {
43     ncurses::pen p (*this);
44    
45     set_color (p);
46     p.move (0, 0);
47     std::string out (str.substr (begin, this->width ()));
48     if (int (out.length ()) < this->width ())
49     out.append (this->width () - out.length (), ' ');
50     p.write (out);
51     }
52    
53     void
54     label::set_color (ncurses::pen &p)
55     {
56     p.set_color (palette::instance ()[colors::label]);
57     }