]> git.lizzy.rs Git - dragonfireclient.git/blob - src/gui/intlGUIEditBox.cpp
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / gui / intlGUIEditBox.cpp
1 // 11.11.2011 11:11 ValkaTR
2 //
3 // This is a copy of intlGUIEditBox from the irrlicht, but with a
4 // fix in the OnEvent function, which doesn't allowed input of
5 // other keyboard layouts than latin-1
6 //
7 // Characters like: ä ö ü õ ы й ю я ъ № € ° ...
8 //
9 // This fix is only needed for linux, because of a bug
10 // in the CIrrDeviceLinux.cpp:1014-1015 of the irrlicht
11 //
12 // Also locale in the programm should not be changed to
13 // a "C", "POSIX" or whatever, it should be set to "",
14 // or XLookupString will return nothing for the international
15 // characters.
16 //
17 // From the "man setlocale":
18 //
19 // On startup of the main program, the portable "C" locale
20 // is selected as default.  A  program  may  be  made
21 // portable to all locales by calling:
22 //
23 //           setlocale(LC_ALL, "");
24 //
25 //       after  program initialization....
26 //
27
28 // Copyright (C) 2002-2013 Nikolaus Gebhardt
29 // This file is part of the "Irrlicht Engine".
30 // For conditions of distribution and use, see copyright notice in irrlicht.h
31
32 #include <util/numeric.h>
33 #include "intlGUIEditBox.h"
34
35 #include "IGUISkin.h"
36 #include "IGUIEnvironment.h"
37 #include "IGUIFont.h"
38 #include "IVideoDriver.h"
39 //#include "irrlicht/os.cpp"
40 #include "porting.h"
41 //#include "Keycodes.h"
42 #include "log.h"
43
44 /*
45         todo:
46         optional scrollbars
47         ctrl+left/right to select word
48         double click/ctrl click: word select + drag to select whole words, triple click to select line
49         optional? dragging selected text
50         numerical
51 */
52
53 namespace irr
54 {
55 namespace gui
56 {
57
58 //! constructor
59 intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border,
60                 IGUIEnvironment* environment, IGUIElement* parent, s32 id,
61                 const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar)
62         : GUIEditBox(environment, parent, id, rectangle, border, writable)
63 {
64         #ifdef _DEBUG
65         setDebugName("intlintlGUIEditBox");
66         #endif
67
68         Text = text;
69
70         if (Environment)
71                 m_operator = Environment->getOSOperator();
72
73         if (m_operator)
74                 m_operator->grab();
75
76         // this element can be tabbed to
77         setTabStop(true);
78         setTabOrder(-1);
79
80         IGUISkin *skin = 0;
81         if (Environment)
82                 skin = Environment->getSkin();
83         if (m_border && skin)
84         {
85                 m_frame_rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
86                 m_frame_rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
87                 m_frame_rect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
88                 m_frame_rect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
89         }
90
91         if (skin && has_vscrollbar) {
92                 m_scrollbar_width = skin->getSize(gui::EGDS_SCROLLBAR_SIZE);
93
94                 if (m_scrollbar_width > 0) {
95                         createVScrollBar();
96                 }
97         }
98
99         breakText();
100
101         calculateScrollPos();
102         setWritable(writable);
103 }
104
105 //! Sets whether to draw the background
106 void intlGUIEditBox::setDrawBackground(bool draw)
107 {
108 }
109
110 void intlGUIEditBox::updateAbsolutePosition()
111 {
112     core::rect<s32> oldAbsoluteRect(AbsoluteRect);
113         IGUIElement::updateAbsolutePosition();
114         if ( oldAbsoluteRect != AbsoluteRect )
115         {
116         breakText();
117         }
118 }
119
120
121 //! draws the element and its children
122 void intlGUIEditBox::draw()
123 {
124         if (!IsVisible)
125                 return;
126
127         const bool focus = Environment->hasFocus(this);
128
129         IGUISkin* skin = Environment->getSkin();
130         if (!skin)
131                 return;
132
133         m_frame_rect = AbsoluteRect;
134
135         // draw the border
136
137         if (m_border)
138         {
139                 if (m_writable) {
140                         skin->draw3DSunkenPane(this, skin->getColor(EGDC_WINDOW),
141                                 false, true, m_frame_rect, &AbsoluteClippingRect);
142                 }
143
144                 m_frame_rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
145                 m_frame_rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
146                 m_frame_rect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
147                 m_frame_rect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
148         }
149
150         updateVScrollBar();
151         core::rect<s32> localClipRect = m_frame_rect;
152         localClipRect.clipAgainst(AbsoluteClippingRect);
153
154         // draw the text
155
156         IGUIFont* font = m_override_font;
157         if (!m_override_font)
158                 font = skin->getFont();
159
160         s32 cursorLine = 0;
161         s32 charcursorpos = 0;
162
163         if (font)
164         {
165                 if (m_last_break_font != font)
166                 {
167                         breakText();
168                 }
169
170                 // calculate cursor pos
171
172                 core::stringw *txtLine = &Text;
173                 s32 startPos = 0;
174
175                 core::stringw s, s2;
176
177                 // get mark position
178                 const bool ml = (!m_passwordbox && (m_word_wrap || m_multiline));
179                 const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
180                 const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
181                 const s32 hlineStart = ml ? getLineFromPos(realmbgn) : 0;
182                 const s32 hlineCount = ml ? getLineFromPos(realmend) - hlineStart + 1 : 1;
183                 const s32 lineCount = ml ? m_broken_text.size() : 1;
184
185                 // Save the override color information.
186                 // Then, alter it if the edit box is disabled.
187                 const bool prevOver = m_override_color_enabled;
188                 const video::SColor prevColor = m_override_color;
189
190                 if (!Text.empty()) {
191                         if (!IsEnabled && !m_override_color_enabled)
192                         {
193                                 m_override_color_enabled = true;
194                                 m_override_color = skin->getColor(EGDC_GRAY_TEXT);
195                         }
196
197                         for (s32 i=0; i < lineCount; ++i)
198                         {
199                                 setTextRect(i);
200
201                                 // clipping test - don't draw anything outside the visible area
202                                 core::rect<s32> c = localClipRect;
203                                 c.clipAgainst(m_current_text_rect);
204                                 if (!c.isValid())
205                                         continue;
206
207                                 // get current line
208                                 if (m_passwordbox)
209                                 {
210                                         if (m_broken_text.size() != 1)
211                                         {
212                                                 m_broken_text.clear();
213                                                 m_broken_text.emplace_back();
214                                         }
215                                         if (m_broken_text[0].size() != Text.size())
216                                         {
217                                                 m_broken_text[0] = Text;
218                                                 for (u32 q = 0; q < Text.size(); ++q)
219                                                 {
220                                                         m_broken_text[0] [q] = m_passwordchar;
221                                                 }
222                                         }
223                                         txtLine = &m_broken_text[0];
224                                         startPos = 0;
225                                 }
226                                 else
227                                 {
228                                         txtLine = ml ? &m_broken_text[i] : &Text;
229                                         startPos = ml ? m_broken_text_positions[i] : 0;
230                                 }
231
232
233                                 // draw normal text
234                                 font->draw(txtLine->c_str(), m_current_text_rect,
235                                         m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
236                                         false, true, &localClipRect);
237
238                                 // draw mark and marked text
239                                 if (focus && m_mark_begin != m_mark_end && i >= hlineStart && i < hlineStart + hlineCount)
240                                 {
241
242                                         s32 mbegin = 0, mend = 0;
243                                         s32 lineStartPos = 0, lineEndPos = txtLine->size();
244
245                                         if (i == hlineStart)
246                                         {
247                                                 // highlight start is on this line
248                                                 s = txtLine->subString(0, realmbgn - startPos);
249                                                 mbegin = font->getDimension(s.c_str()).Width;
250
251                                                 // deal with kerning
252                                                 mbegin += font->getKerningWidth(
253                                                         &((*txtLine)[realmbgn - startPos]),
254                                                         realmbgn - startPos > 0 ? &((*txtLine)[realmbgn - startPos - 1]) : 0);
255
256                                                 lineStartPos = realmbgn - startPos;
257                                         }
258                                         if (i == hlineStart + hlineCount - 1)
259                                         {
260                                                 // highlight end is on this line
261                                                 s2 = txtLine->subString(0, realmend - startPos);
262                                                 mend = font->getDimension(s2.c_str()).Width;
263                                                 lineEndPos = (s32)s2.size();
264                                         }
265                                         else
266                                                 mend = font->getDimension(txtLine->c_str()).Width;
267
268                                         m_current_text_rect.UpperLeftCorner.X += mbegin;
269                                         m_current_text_rect.LowerRightCorner.X = m_current_text_rect.UpperLeftCorner.X + mend - mbegin;
270
271                                         // draw mark
272                                         skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), m_current_text_rect, &localClipRect);
273
274                                         // draw marked text
275                                         s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos);
276
277                                         if (!s.empty())
278                                                 font->draw(s.c_str(), m_current_text_rect,
279                                                         m_override_color_enabled ? m_override_color : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
280                                                         false, true, &localClipRect);
281
282                                 }
283                         }
284
285                         // Return the override color information to its previous settings.
286                         m_override_color_enabled = prevOver;
287                         m_override_color = prevColor;
288                 }
289
290                 // draw cursor
291
292                 if (m_word_wrap || m_multiline)
293                 {
294                         cursorLine = getLineFromPos(m_cursor_pos);
295                         txtLine = &m_broken_text[cursorLine];
296                         startPos = m_broken_text_positions[cursorLine];
297                 }
298                 s = txtLine->subString(0,m_cursor_pos-startPos);
299                 charcursorpos = font->getDimension(s.c_str()).Width +
300                         font->getKerningWidth(L"_", m_cursor_pos-startPos > 0 ? &((*txtLine)[m_cursor_pos-startPos-1]) : 0);
301
302                 if (m_writable) {
303                         if (focus && (porting::getTimeMs() - m_blink_start_time) % 700 < 350) {
304                                 setTextRect(cursorLine);
305                                 m_current_text_rect.UpperLeftCorner.X += charcursorpos;
306
307                                 font->draw(L"_", m_current_text_rect,
308                                         m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
309                                         false, true, &localClipRect);
310                         }
311                 }
312         }
313
314         // draw children
315         IGUIElement::draw();
316 }
317
318
319 s32 intlGUIEditBox::getCursorPos(s32 x, s32 y)
320 {
321         IGUIFont* font = m_override_font;
322         IGUISkin* skin = Environment->getSkin();
323         if (!m_override_font)
324                 font = skin->getFont();
325
326         const u32 lineCount = (m_word_wrap || m_multiline) ? m_broken_text.size() : 1;
327
328         core::stringw *txtLine = NULL;
329         s32 startPos = 0;
330         u32 curr_line_idx = 0;
331         x += 3;
332
333         for (; curr_line_idx < lineCount; ++curr_line_idx) {
334                 setTextRect(curr_line_idx);
335                 if (curr_line_idx == 0 && y < m_current_text_rect.UpperLeftCorner.Y)
336                         y = m_current_text_rect.UpperLeftCorner.Y;
337                 if (curr_line_idx == lineCount - 1 && y > m_current_text_rect.LowerRightCorner.Y)
338                         y = m_current_text_rect.LowerRightCorner.Y;
339
340                 // is it inside this region?
341                 if (y >= m_current_text_rect.UpperLeftCorner.Y && y <= m_current_text_rect.LowerRightCorner.Y) {
342                         // we've found the clicked line
343                         txtLine = (m_word_wrap || m_multiline) ? &m_broken_text[curr_line_idx] : &Text;
344                         startPos = (m_word_wrap || m_multiline) ? m_broken_text_positions[curr_line_idx] : 0;
345                         break;
346                 }
347         }
348
349         if (x < m_current_text_rect.UpperLeftCorner.X)
350                 x = m_current_text_rect.UpperLeftCorner.X;
351         else if (x > m_current_text_rect.LowerRightCorner.X)
352                 x = m_current_text_rect.LowerRightCorner.X;
353
354         s32 idx = font->getCharacterFromPos(txtLine->c_str(), x - m_current_text_rect.UpperLeftCorner.X);
355         // Special handling for last line, if we are on limits, add 1 extra shift because idx
356         // will be the last char, not null char of the wstring
357         if (curr_line_idx == lineCount - 1 && x == m_current_text_rect.LowerRightCorner.X)
358                 idx++;
359
360         return rangelim(idx + startPos, 0, S32_MAX);
361 }
362
363
364 //! Breaks the single text line.
365 void intlGUIEditBox::breakText()
366 {
367         IGUISkin* skin = Environment->getSkin();
368
369         if ((!m_word_wrap && !m_multiline) || !skin)
370                 return;
371
372         m_broken_text.clear(); // need to reallocate :/
373         m_broken_text_positions.clear();
374
375         IGUIFont* font = m_override_font;
376         if (!m_override_font)
377                 font = skin->getFont();
378
379         if (!font)
380                 return;
381
382         m_last_break_font = font;
383
384         core::stringw line;
385         core::stringw word;
386         core::stringw whitespace;
387         s32 lastLineStart = 0;
388         s32 size = Text.size();
389         s32 length = 0;
390         s32 elWidth = RelativeRect.getWidth() - m_scrollbar_width - 10;
391         wchar_t c;
392
393         for (s32 i=0; i<size; ++i)
394         {
395                 c = Text[i];
396                 bool lineBreak = false;
397
398                 if (c == L'\r') // Mac or Windows breaks
399                 {
400                         lineBreak = true;
401                         c = ' ';
402                         if (Text[i+1] == L'\n') // Windows breaks
403                         {
404                                 Text.erase(i+1);
405                                 --size;
406                         }
407                 }
408                 else if (c == L'\n') // Unix breaks
409                 {
410                         lineBreak = true;
411                         c = ' ';
412                 }
413
414                 // don't break if we're not a multi-line edit box
415                 if (!m_multiline)
416                         lineBreak = false;
417
418                 if (c == L' ' || c == 0 || i == (size-1))
419                 {
420                         if (!word.empty()) {
421                                 // here comes the next whitespace, look if
422                                 // we can break the last word to the next line.
423                                 s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
424                                 s32 worldlgth = font->getDimension(word.c_str()).Width;
425
426                                 if (m_word_wrap && length + worldlgth + whitelgth > elWidth)
427                                 {
428                                         // break to next line
429                                         length = worldlgth;
430                                         m_broken_text.push_back(line);
431                                         m_broken_text_positions.push_back(lastLineStart);
432                                         lastLineStart = i - (s32)word.size();
433                                         line = word;
434                                 }
435                                 else
436                                 {
437                                         // add word to line
438                                         line += whitespace;
439                                         line += word;
440                                         length += whitelgth + worldlgth;
441                                 }
442
443                                 word = L"";
444                                 whitespace = L"";
445                         }
446
447                         whitespace += c;
448
449                         // compute line break
450                         if (lineBreak)
451                         {
452                                 line += whitespace;
453                                 line += word;
454                                 m_broken_text.push_back(line);
455                                 m_broken_text_positions.push_back(lastLineStart);
456                                 lastLineStart = i+1;
457                                 line = L"";
458                                 word = L"";
459                                 whitespace = L"";
460                                 length = 0;
461                         }
462                 }
463                 else
464                 {
465                         // yippee this is a word..
466                         word += c;
467                 }
468         }
469
470         line += whitespace;
471         line += word;
472         m_broken_text.push_back(line);
473         m_broken_text_positions.push_back(lastLineStart);
474 }
475
476
477 void intlGUIEditBox::setTextRect(s32 line)
478 {
479         core::dimension2du d;
480
481         IGUISkin* skin = Environment->getSkin();
482         if (!skin)
483                 return;
484
485         IGUIFont* font = m_override_font ? m_override_font : skin->getFont();
486
487         if (!font)
488                 return;
489
490         // get text dimension
491         const u32 lineCount = (m_word_wrap || m_multiline) ? m_broken_text.size() : 1;
492         if (m_word_wrap || m_multiline)
493         {
494                 d = font->getDimension(m_broken_text[line].c_str());
495         }
496         else
497         {
498                 d = font->getDimension(Text.c_str());
499                 d.Height = AbsoluteRect.getHeight();
500         }
501         d.Height += font->getKerningHeight();
502
503         // justification
504         switch (m_halign)
505         {
506         case EGUIA_CENTER:
507                 // align to h centre
508                 m_current_text_rect.UpperLeftCorner.X = (m_frame_rect.getWidth()/2) - (d.Width/2);
509                 m_current_text_rect.LowerRightCorner.X = (m_frame_rect.getWidth()/2) + (d.Width/2);
510                 break;
511         case EGUIA_LOWERRIGHT:
512                 // align to right edge
513                 m_current_text_rect.UpperLeftCorner.X = m_frame_rect.getWidth() - d.Width;
514                 m_current_text_rect.LowerRightCorner.X = m_frame_rect.getWidth();
515                 break;
516         default:
517                 // align to left edge
518                 m_current_text_rect.UpperLeftCorner.X = 0;
519                 m_current_text_rect.LowerRightCorner.X = d.Width;
520
521         }
522
523         switch (m_valign)
524         {
525         case EGUIA_CENTER:
526                 // align to v centre
527                 m_current_text_rect.UpperLeftCorner.Y =
528                         (m_frame_rect.getHeight()/2) - (lineCount*d.Height)/2 + d.Height*line;
529                 break;
530         case EGUIA_LOWERRIGHT:
531                 // align to bottom edge
532                 m_current_text_rect.UpperLeftCorner.Y =
533                         m_frame_rect.getHeight() - lineCount*d.Height + d.Height*line;
534                 break;
535         default:
536                 // align to top edge
537                 m_current_text_rect.UpperLeftCorner.Y = d.Height*line;
538                 break;
539         }
540
541         m_current_text_rect.UpperLeftCorner.X  -= m_hscroll_pos;
542         m_current_text_rect.LowerRightCorner.X -= m_hscroll_pos;
543         m_current_text_rect.UpperLeftCorner.Y  -= m_vscroll_pos;
544         m_current_text_rect.LowerRightCorner.Y = m_current_text_rect.UpperLeftCorner.Y + d.Height;
545
546         m_current_text_rect += m_frame_rect.UpperLeftCorner;
547
548 }
549
550 void intlGUIEditBox::inputChar(wchar_t c)
551 {
552         if (!isEnabled() || !m_writable)
553                 return;
554
555         if (c != 0)
556         {
557                 if (Text.size() < m_max || m_max == 0)
558                 {
559                         core::stringw s;
560
561                         if (m_mark_begin != m_mark_end)
562                         {
563                                 // replace marked text
564                                 const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
565                                 const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
566
567                                 s = Text.subString(0, realmbgn);
568                                 s.append(c);
569                                 s.append( Text.subString(realmend, Text.size()-realmend) );
570                                 Text = s;
571                                 m_cursor_pos = realmbgn+1;
572                         }
573                         else
574                         {
575                                 // add new character
576                                 s = Text.subString(0, m_cursor_pos);
577                                 s.append(c);
578                                 s.append( Text.subString(m_cursor_pos, Text.size()-m_cursor_pos) );
579                                 Text = s;
580                                 ++m_cursor_pos;
581                         }
582
583                         m_blink_start_time = porting::getTimeMs();
584                         setTextMarkers(0, 0);
585                 }
586         }
587         breakText();
588         sendGuiEvent(EGET_EDITBOX_CHANGED);
589         calculateScrollPos();
590 }
591
592
593 void intlGUIEditBox::calculateScrollPos()
594 {
595         if (!m_autoscroll)
596                 return;
597
598         // calculate horizontal scroll position
599         s32 cursLine = getLineFromPos(m_cursor_pos);
600         setTextRect(cursLine);
601
602         // don't do horizontal scrolling when wordwrap is enabled.
603         if (!m_word_wrap)
604         {
605                 // get cursor position
606                 IGUISkin* skin = Environment->getSkin();
607                 if (!skin)
608                         return;
609                 IGUIFont* font = m_override_font ? m_override_font : skin->getFont();
610                 if (!font)
611                         return;
612
613                 core::stringw *txtLine = m_multiline ? &m_broken_text[cursLine] : &Text;
614                 s32 cPos = m_multiline ? m_cursor_pos - m_broken_text_positions[cursLine] : m_cursor_pos;
615
616                 s32 cStart = m_current_text_rect.UpperLeftCorner.X + m_hscroll_pos +
617                         font->getDimension(txtLine->subString(0, cPos).c_str()).Width;
618
619                 s32 cEnd = cStart + font->getDimension(L"_ ").Width;
620
621                 if (m_frame_rect.LowerRightCorner.X < cEnd)
622                         m_hscroll_pos = cEnd - m_frame_rect.LowerRightCorner.X;
623                 else if (m_frame_rect.UpperLeftCorner.X > cStart)
624                         m_hscroll_pos = cStart - m_frame_rect.UpperLeftCorner.X;
625                 else
626                         m_hscroll_pos = 0;
627
628                 // todo: adjust scrollbar
629         }
630
631         if (!m_word_wrap && !m_multiline)
632                 return;
633
634         // vertical scroll position
635         if (m_frame_rect.LowerRightCorner.Y < m_current_text_rect.LowerRightCorner.Y)
636                 m_vscroll_pos += m_current_text_rect.LowerRightCorner.Y - m_frame_rect.LowerRightCorner.Y; // scrolling downwards
637         else if (m_frame_rect.UpperLeftCorner.Y > m_current_text_rect.UpperLeftCorner.Y)
638                 m_vscroll_pos += m_current_text_rect.UpperLeftCorner.Y - m_frame_rect.UpperLeftCorner.Y; // scrolling upwards
639
640         // todo: adjust scrollbar
641         if (m_vscrollbar)
642                 m_vscrollbar->setPos(m_vscroll_pos);
643 }
644
645
646 //! Create a vertical scrollbar
647 void intlGUIEditBox::createVScrollBar()
648 {
649         s32 fontHeight = 1;
650
651         if (m_override_font) {
652                 fontHeight = m_override_font->getDimension(L"").Height;
653         } else {
654                 if (IGUISkin* skin = Environment->getSkin()) {
655                         if (IGUIFont* font = skin->getFont()) {
656                                 fontHeight = font->getDimension(L"").Height;
657                         }
658                 }
659         }
660
661         irr::core::rect<s32> scrollbarrect = m_frame_rect;
662         scrollbarrect.UpperLeftCorner.X += m_frame_rect.getWidth() - m_scrollbar_width;
663         m_vscrollbar = new GUIScrollBar(Environment, getParent(), -1,
664                         scrollbarrect, false, true);
665
666         m_vscrollbar->setVisible(false);
667         m_vscrollbar->setSmallStep(3 * fontHeight);
668         m_vscrollbar->setLargeStep(10 * fontHeight);
669 }
670
671
672 //! Writes attributes of the element.
673 void intlGUIEditBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
674 {
675         // IGUIEditBox::serializeAttributes(out,options);
676
677         out->addBool  ("OverrideColorEnabled", m_override_color_enabled );
678         out->addColor ("OverrideColor",        m_override_color);
679         // out->addFont("OverrideFont",m_override_font);
680         out->addInt   ("MaxChars",             m_max);
681         out->addBool  ("WordWrap",             m_word_wrap);
682         out->addBool  ("MultiLine",            m_multiline);
683         out->addBool  ("AutoScroll",           m_autoscroll);
684         out->addBool  ("PasswordBox",          m_passwordbox);
685         core::stringw ch = L" ";
686         ch[0] = m_passwordchar;
687         out->addString("PasswordChar",         ch.c_str());
688         out->addEnum  ("HTextAlign",           m_halign, GUIAlignmentNames);
689         out->addEnum  ("VTextAlign",           m_valign, GUIAlignmentNames);
690         out->addBool  ("Writable",             m_writable);
691
692         IGUIEditBox::serializeAttributes(out,options);
693 }
694
695
696 //! Reads attributes of the element
697 void intlGUIEditBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
698 {
699         IGUIEditBox::deserializeAttributes(in,options);
700
701         setOverrideColor(in->getAttributeAsColor("OverrideColor"));
702         enableOverrideColor(in->getAttributeAsBool("OverrideColorEnabled"));
703         setMax(in->getAttributeAsInt("MaxChars"));
704         setWordWrap(in->getAttributeAsBool("WordWrap"));
705         setMultiLine(in->getAttributeAsBool("MultiLine"));
706         setAutoScroll(in->getAttributeAsBool("AutoScroll"));
707         core::stringw ch = in->getAttributeAsStringW("PasswordChar");
708
709         if (ch.empty())
710                 setPasswordBox(in->getAttributeAsBool("PasswordBox"));
711         else
712                 setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]);
713
714         setTextAlignment( (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("HTextAlign", GUIAlignmentNames),
715                         (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("VTextAlign", GUIAlignmentNames));
716
717         setWritable(in->getAttributeAsBool("Writable"));
718         // setOverrideFont(in->getAttributeAsFont("OverrideFont"));
719 }
720
721
722 } // end namespace gui
723 } // end namespace irr