ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/dclient/src/backend/ndk/edit.cpp
(Generate patch)

Comparing deliantra/dclient/src/backend/ndk/edit.cpp (file contents):
Revision 1.3 by sf-pippijn, Mon Oct 18 15:34:23 2010 UTC vs.
Revision 1.8 by sf-pippijn, Fri Jan 21 21:54:01 2011 UTC

1/* edit.cc 1/* edit.cc
2 * This file is part of NDK++ library 2 * This file is part of NDK++ library
3 * Copyright (c) 2003,2004 by Stanislav Ievlev 3 * Copyright (c) 2003,2004 by Stanislav Ievlev
4 * 4 *
5 * This file is covered by the GNU Library General Public License, 5 * This file is covered by the GNU Library General Public License,
6 * which should be included with libndk++ as the file COPYING. 6 * which should be included with libndk as the file COPYING.
7 */ 7 */
8#include <ndk++/application.hh> 8#include <ndk/application.hh>
9#include <ndk++/edit.hh> 9#include <ndk/edit.hh>
10#include <ndk++/packer.hh> 10#include <ndk/packer.hh>
11#include <ndk++/palette.hh> 11#include <ndk/palette.hh>
12 12
13#include <ncurses/assert.hh>
14#include <ncurses/pen.hh> 13#include <ndk/pen.hh>
15 14
16#include <cctype> 15#include <cctype>
17 16
18 17
19using ndk::edit; 18using ndk::edit;
49} 48}
50 49
51void 50void
52edit::change_color () 51edit::change_color ()
53{ 52{
54 ncurses::pen (*this).set_color (palette::instance () 53 pen (*this).set_color (palette::instance ().find (
55 [
56 state_ == engine::enter_focus 54 state_ == engine::enter_focus
57 ? colors::edit_active 55 ? colors::edit_active
58 : colors::edit_inactive 56 : colors::edit_inactive
59 ]); 57 )->second);
60} 58}
61 59
62void 60void
63edit::draw () 61edit::draw ()
64{ 62{
78 break; 76 break;
79 default: 77 default:
80 break; 78 break;
81 } 79 }
82 80
81 if (begin_ > out.length ())
82 begin_ = out.length ();
83
83 label::draw (out, begin_); /* and draw */ 84 label::draw (out, begin_); /* and draw */
84 set_cursor (); /* and finally update cursor position */ 85 set_cursor (); /* and finally update cursor position */
85 ncurses::pen (*this).commit (); /* commit changes to the screen */ 86 pen (*this).commit (); /* commit changes to the screen */
86} 87}
87 88
88ndk::event::result 89ndk::event::result
89edit::at_system (event const &ev) 90edit::at_system (event const &ev)
90{ 91{
92 93
93 if (!ev.sender_) 94 if (!ev.sender_)
94 { 95 {
95 if (engine::enter_focus == ev.type_) 96 if (engine::enter_focus == ev.type_)
96 { 97 {
97 app ().cursor_on (); 98 app->cursor_on ();
98 set_cursor (); /* only set cursor position, don't need full redraw */ 99 set_cursor (); /* only set cursor position, don't need full redraw */
99 res = event::accepted; 100 res = event::accepted;
100 } 101 }
101 else if (engine::leave_focus == ev.type_) 102 else if (engine::leave_focus == ev.type_)
102 { 103 {
103 app ().cursor_off (); 104 app->cursor_off ();
104 res = event::accepted; 105 res = event::accepted;
105 } 106 }
106 } 107 }
107 return res; 108 return res;
108} 109}
138 { 139 {
139 erase (pos); 140 erase (pos);
140 draw (); /* we always need full redraw */ 141 draw (); /* we always need full redraw */
141 res = event::accepted; 142 res = event::accepted;
142 } 143 }
144 break;
145 case key::ctrl_u:
146 if (pos)
147 {
148 /* delete all characters up to the current */
149 text_ = text_.substr (pos, text_.length () - pos);
150 current_ = 0;
151 recalibrate (); // TODO: ? draw () : set_cursor (); // or always draw?
152 draw ();
153 pos = 0;
154 }
155 res = event::accepted;
143 break; 156 break;
144 case key::home: 157 case key::home:
145 begin_ = 0; 158 begin_ = 0;
146 current_ = 0; 159 current_ = 0;
147 draw (); 160 draw ();
215 228
216void 229void
217edit::set_cursor () 230edit::set_cursor ()
218{ 231{
219 /* always move to zero position in no_echo mode */ 232 /* always move to zero position in no_echo mode */
220 return_unless (ncurses::pen (*this).move (mode_ != no_echo ? current_ - begin_ : 0, 0)); 233 return_unless (pen (*this).move (mode_ != no_echo ? current_ - begin_ : 0, 0));
221 ncurses::pen (*this).commit (); 234 pen (*this).commit ();
222} 235}
223 236
224void 237void
225edit::insert (int pos, char sym) 238edit::insert (int pos, char sym)
226{ 239{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines