ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ndk/label.cpp
Revision: 1.5
Committed: Tue Oct 19 09:45:08 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.4: +4 -4 lines
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 /* 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.3 using ndk::label;
12 sf-pippijn 1.1
13 sf-pippijn 1.3 label::label (std::string const &str, ndk::panel *parent)
14 sf-pippijn 1.5 : panel (parent)
15 sf-pippijn 1.1 , 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 sf-pippijn 1.3 label::set_text (std::string const &str)
24 sf-pippijn 1.1 {
25     text_ = str;
26     }
27    
28 sf-pippijn 1.3 std::string const &
29 sf-pippijn 1.1 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 sf-pippijn 1.3 label::draw (std::string const &str, std::string::size_type begin)
42 sf-pippijn 1.1 {
43 sf-pippijn 1.5 pen p (*this);
44 sf-pippijn 1.1
45     set_color (p);
46 sf-pippijn 1.2 return_unless (p.move (0, 0));
47 sf-pippijn 1.1 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 sf-pippijn 1.5 label::set_color (pen &p)
55 sf-pippijn 1.1 {
56 sf-pippijn 1.5 p.set_color (palette::instance ().find (colors::label)->second);
57 sf-pippijn 1.1 }