1 //**************************************************************************
3 //** ## ## ## ## ## #### #### ### ###
4 //** ## ## ## ## ## ## ## ## ## ## #### ####
5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ##
6 //** ## ## ######## ## ## ## ## ## ## ## ### ##
7 //** ### ## ## ### ## ## ## ## ## ##
8 //** # ## ## # #### #### ## ##
10 //** Copyright (C) 1999-2006 Jānis Legzdiņš
11 //** Copyright (C) 2018-2023 Ketmar Dark
13 //** This program is free software: you can redistribute it and/or modify
14 //** it under the terms of the GNU General Public License as published by
15 //** the Free Software Foundation, version 3 of the License ONLY.
17 //** This program is distributed in the hope that it will be useful,
18 //** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 //** GNU General Public License for more details.
22 //** You should have received a copy of the GNU General Public License
23 //** along with this program. If not, see <http://www.gnu.org/licenses/>.
25 //**************************************************************************
27 //** input line library
29 //**************************************************************************
30 #ifndef CL_ILINE_HEADER
31 #define CL_ILINE_HEADER
34 // input text line widget
37 char *data
; // line of text (zero-terminated)
38 int len
; // current line length
41 int vischars
; // number of on-screen visible chars
42 int visfirst
; // first visible char in current string
43 // temp buffer for renderer
50 void ensureCursorVisible ();
56 TILine () : data(nullptr), len(0), maxlen(0), curpos(0), vischars(80), visfirst(0), temp(nullptr), tempsize(0), cursorChar('_') { setup(); }
57 TILine (int amaxlen
) : data(nullptr), len(0), maxlen(amaxlen
), curpos(0), vischars(80), visfirst(0), temp(nullptr), tempsize(0), cursorChar('_') { setup(); }
60 inline int length () const { return len
; }
61 inline int maxLength () const { return maxlen
; }
62 inline const char *getCStr () const { return data
; }
63 inline const char *operator * () const { return data
; }
65 inline int getCurPos () const { return clampval(curpos
, 0, len
); }
66 inline void setCurPos (int cpos
) { curpos
= cpos
; ensureCursorVisible(); }
68 void SetVisChars (int vc
);
71 void AddString (VStr s
);
72 void AddString (const char *s
);
73 void AddChar (char ch
);
74 void DelChar (); // this does "backspace"
75 void RemoveChar (); // this removes char at the current cursor position, and doesn't move cursor
79 bool Key (const event_t
&ev
); // whether eaten
81 // font and align should be already set
82 void DrawAt (int x0
, int y0
, int clrNormal
=CR_ORANGE
, int clrLR
=CR_FIRE
);