guiEditBoxWithScrollbar.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // Modified by Mustapha T.
  3. // This file is part of the "Irrlicht Engine".
  4. // For conditions of distribution and use, see copyright notice in irrlicht.h
  5. #include "guiEditBoxWithScrollbar.h"
  6. #include "IGUISkin.h"
  7. #include "IGUIEnvironment.h"
  8. #include "IGUIFont.h"
  9. #include "IVideoDriver.h"
  10. #include "rect.h"
  11. #include "porting.h"
  12. #include "Keycodes.h"
  13. /*
  14. todo:
  15. optional scrollbars [done]
  16. ctrl+left/right to select word
  17. double click/ctrl click: word select + drag to select whole words, triple click to select line
  18. optional? dragging selected text
  19. numerical
  20. */
  21. //! constructor
  22. GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool border,
  23. IGUIEnvironment* environment, IGUIElement* parent, s32 id,
  24. const core::rect<s32>& rectangle, ISimpleTextureSource *tsrc,
  25. bool writable, bool has_vscrollbar)
  26. : GUIEditBox(environment, parent, id, rectangle, border, writable),
  27. m_background(true), m_bg_color_used(false), m_tsrc(tsrc)
  28. {
  29. #ifdef _DEBUG
  30. setDebugName("GUIEditBoxWithScrollBar");
  31. #endif
  32. Text = text;
  33. if (Environment)
  34. m_operator = Environment->getOSOperator();
  35. if (m_operator)
  36. m_operator->grab();
  37. // this element can be tabbed to
  38. setTabStop(true);
  39. setTabOrder(-1);
  40. if (has_vscrollbar) {
  41. createVScrollBar();
  42. }
  43. calculateFrameRect();
  44. breakText();
  45. calculateScrollPos();
  46. setWritable(writable);
  47. }
  48. //! Sets whether to draw the background
  49. void GUIEditBoxWithScrollBar::setDrawBackground(bool draw)
  50. {
  51. m_background = draw;
  52. }
  53. void GUIEditBoxWithScrollBar::updateAbsolutePosition()
  54. {
  55. core::rect<s32> old_absolute_rect(AbsoluteRect);
  56. IGUIElement::updateAbsolutePosition();
  57. if (old_absolute_rect != AbsoluteRect) {
  58. calculateFrameRect();
  59. breakText();
  60. calculateScrollPos();
  61. }
  62. }
  63. //! draws the element and its children
  64. void GUIEditBoxWithScrollBar::draw()
  65. {
  66. if (!IsVisible)
  67. return;
  68. const bool focus = Environment->hasFocus(this);
  69. IGUISkin* skin = Environment->getSkin();
  70. if (!skin)
  71. return;
  72. video::SColor default_bg_color;
  73. video::SColor bg_color;
  74. default_bg_color = m_writable ? skin->getColor(EGDC_WINDOW) : video::SColor(0);
  75. bg_color = m_bg_color_used ? m_bg_color : default_bg_color;
  76. if (!m_border && m_background) {
  77. skin->draw2DRectangle(this, bg_color, AbsoluteRect, &AbsoluteClippingRect);
  78. }
  79. // draw the border
  80. if (m_border) {
  81. if (m_writable) {
  82. skin->draw3DSunkenPane(this, bg_color, false, m_background,
  83. AbsoluteRect, &AbsoluteClippingRect);
  84. }
  85. }
  86. calculateFrameRect();
  87. core::rect<s32> local_clip_rect = m_frame_rect;
  88. local_clip_rect.clipAgainst(AbsoluteClippingRect);
  89. // draw the text
  90. IGUIFont* font = getActiveFont();
  91. s32 cursor_line = 0;
  92. s32 charcursorpos = 0;
  93. if (font) {
  94. if (m_last_break_font != font) {
  95. breakText();
  96. }
  97. // calculate cursor pos
  98. core::stringw *txt_line = &Text;
  99. s32 start_pos = 0;
  100. core::stringw s, s2;
  101. // get mark position
  102. const bool ml = (!m_passwordbox && (m_word_wrap || m_multiline));
  103. const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
  104. const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
  105. const s32 hline_start = ml ? getLineFromPos(realmbgn) : 0;
  106. const s32 hline_count = ml ? getLineFromPos(realmend) - hline_start + 1 : 1;
  107. const s32 line_count = ml ? m_broken_text.size() : 1;
  108. // Save the override color information.
  109. // Then, alter it if the edit box is disabled.
  110. const bool prevOver = m_override_color_enabled;
  111. const video::SColor prevColor = m_override_color;
  112. if (Text.size()) {
  113. if (!isEnabled() && !m_override_color_enabled) {
  114. m_override_color_enabled = true;
  115. m_override_color = skin->getColor(EGDC_GRAY_TEXT);
  116. }
  117. for (s32 i = 0; i < line_count; ++i) {
  118. setTextRect(i);
  119. // clipping test - don't draw anything outside the visible area
  120. core::rect<s32> c = local_clip_rect;
  121. c.clipAgainst(m_current_text_rect);
  122. if (!c.isValid())
  123. continue;
  124. // get current line
  125. if (m_passwordbox) {
  126. if (m_broken_text.size() != 1) {
  127. m_broken_text.clear();
  128. m_broken_text.emplace_back();
  129. }
  130. if (m_broken_text[0].size() != Text.size()){
  131. m_broken_text[0] = Text;
  132. for (u32 q = 0; q < Text.size(); ++q)
  133. {
  134. m_broken_text[0][q] = m_passwordchar;
  135. }
  136. }
  137. txt_line = &m_broken_text[0];
  138. start_pos = 0;
  139. } else {
  140. txt_line = ml ? &m_broken_text[i] : &Text;
  141. start_pos = ml ? m_broken_text_positions[i] : 0;
  142. }
  143. // draw normal text
  144. font->draw(txt_line->c_str(), m_current_text_rect,
  145. m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
  146. false, true, &local_clip_rect);
  147. // draw mark and marked text
  148. if (focus && m_mark_begin != m_mark_end && i >= hline_start && i < hline_start + hline_count) {
  149. s32 mbegin = 0, mend = 0;
  150. s32 lineStartPos = 0, lineEndPos = txt_line->size();
  151. if (i == hline_start) {
  152. // highlight start is on this line
  153. s = txt_line->subString(0, realmbgn - start_pos);
  154. mbegin = font->getDimension(s.c_str()).Width;
  155. // deal with kerning
  156. mbegin += font->getKerningWidth(
  157. &((*txt_line)[realmbgn - start_pos]),
  158. realmbgn - start_pos > 0 ? &((*txt_line)[realmbgn - start_pos - 1]) : 0);
  159. lineStartPos = realmbgn - start_pos;
  160. }
  161. if (i == hline_start + hline_count - 1) {
  162. // highlight end is on this line
  163. s2 = txt_line->subString(0, realmend - start_pos);
  164. mend = font->getDimension(s2.c_str()).Width;
  165. lineEndPos = (s32)s2.size();
  166. } else {
  167. mend = font->getDimension(txt_line->c_str()).Width;
  168. }
  169. m_current_text_rect.UpperLeftCorner.X += mbegin;
  170. m_current_text_rect.LowerRightCorner.X = m_current_text_rect.UpperLeftCorner.X + mend - mbegin;
  171. // draw mark
  172. skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), m_current_text_rect, &local_clip_rect);
  173. // draw marked text
  174. s = txt_line->subString(lineStartPos, lineEndPos - lineStartPos);
  175. if (s.size())
  176. font->draw(s.c_str(), m_current_text_rect,
  177. m_override_color_enabled ? m_override_color : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
  178. false, true, &local_clip_rect);
  179. }
  180. }
  181. // Return the override color information to its previous settings.
  182. m_override_color_enabled = prevOver;
  183. m_override_color = prevColor;
  184. }
  185. // draw cursor
  186. if (IsEnabled && m_writable) {
  187. if (m_word_wrap || m_multiline) {
  188. cursor_line = getLineFromPos(m_cursor_pos);
  189. txt_line = &m_broken_text[cursor_line];
  190. start_pos = m_broken_text_positions[cursor_line];
  191. }
  192. s = txt_line->subString(0, m_cursor_pos - start_pos);
  193. charcursorpos = font->getDimension(s.c_str()).Width +
  194. font->getKerningWidth(L"_", m_cursor_pos - start_pos > 0 ? &((*txt_line)[m_cursor_pos - start_pos - 1]) : 0);
  195. if (focus && (porting::getTimeMs() - m_blink_start_time) % 700 < 350) {
  196. setTextRect(cursor_line);
  197. m_current_text_rect.UpperLeftCorner.X += charcursorpos;
  198. font->draw(L"_", m_current_text_rect,
  199. m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
  200. false, true, &local_clip_rect);
  201. }
  202. }
  203. }
  204. // draw children
  205. IGUIElement::draw();
  206. }
  207. s32 GUIEditBoxWithScrollBar::getCursorPos(s32 x, s32 y)
  208. {
  209. IGUIFont* font = getActiveFont();
  210. const u32 line_count = (m_word_wrap || m_multiline) ? m_broken_text.size() : 1;
  211. core::stringw *txt_line = 0;
  212. s32 start_pos = 0;
  213. x += 3;
  214. for (u32 i = 0; i < line_count; ++i) {
  215. setTextRect(i);
  216. if (i == 0 && y < m_current_text_rect.UpperLeftCorner.Y)
  217. y = m_current_text_rect.UpperLeftCorner.Y;
  218. if (i == line_count - 1 && y > m_current_text_rect.LowerRightCorner.Y)
  219. y = m_current_text_rect.LowerRightCorner.Y;
  220. // is it inside this region?
  221. if (y >= m_current_text_rect.UpperLeftCorner.Y && y <= m_current_text_rect.LowerRightCorner.Y) {
  222. // we've found the clicked line
  223. txt_line = (m_word_wrap || m_multiline) ? &m_broken_text[i] : &Text;
  224. start_pos = (m_word_wrap || m_multiline) ? m_broken_text_positions[i] : 0;
  225. break;
  226. }
  227. }
  228. if (x < m_current_text_rect.UpperLeftCorner.X)
  229. x = m_current_text_rect.UpperLeftCorner.X;
  230. if (!txt_line)
  231. return 0;
  232. s32 idx = font->getCharacterFromPos(txt_line->c_str(), x - m_current_text_rect.UpperLeftCorner.X);
  233. // click was on or left of the line
  234. if (idx != -1)
  235. return idx + start_pos;
  236. // click was off the right edge of the line, go to end.
  237. return txt_line->size() + start_pos;
  238. }
  239. //! Breaks the single text line.
  240. void GUIEditBoxWithScrollBar::breakText()
  241. {
  242. if ((!m_word_wrap && !m_multiline))
  243. return;
  244. m_broken_text.clear(); // need to reallocate :/
  245. m_broken_text_positions.clear();
  246. IGUIFont* font = getActiveFont();
  247. if (!font)
  248. return;
  249. m_last_break_font = font;
  250. core::stringw line;
  251. core::stringw word;
  252. core::stringw whitespace;
  253. s32 last_line_start = 0;
  254. s32 size = Text.size();
  255. s32 length = 0;
  256. s32 el_width = RelativeRect.getWidth() - m_scrollbar_width - 10;
  257. wchar_t c;
  258. for (s32 i = 0; i < size; ++i) {
  259. c = Text[i];
  260. bool line_break = false;
  261. if (c == L'\r') { // Mac or Windows breaks
  262. line_break = true;
  263. c = 0;
  264. if (Text[i + 1] == L'\n') { // Windows breaks
  265. // TODO: I (Michael) think that we shouldn't change the text given by the user for whatever reason.
  266. // Instead rework the cursor positioning to be able to handle this (but not in stable release
  267. // branch as users might already expect this behavior).
  268. Text.erase(i + 1);
  269. --size;
  270. if (m_cursor_pos > i)
  271. --m_cursor_pos;
  272. }
  273. } else if (c == L'\n') { // Unix breaks
  274. line_break = true;
  275. c = 0;
  276. }
  277. // don't break if we're not a multi-line edit box
  278. if (!m_multiline)
  279. line_break = false;
  280. if (c == L' ' || c == 0 || i == (size - 1)) {
  281. // here comes the next whitespace, look if
  282. // we can break the last word to the next line
  283. // We also break whitespace, otherwise cursor would vanish beside the right border.
  284. s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
  285. s32 worldlgth = font->getDimension(word.c_str()).Width;
  286. if (m_word_wrap && length + worldlgth + whitelgth > el_width && line.size() > 0) {
  287. // break to next line
  288. length = worldlgth;
  289. m_broken_text.push_back(line);
  290. m_broken_text_positions.push_back(last_line_start);
  291. last_line_start = i - (s32)word.size();
  292. line = word;
  293. } else {
  294. // add word to line
  295. line += whitespace;
  296. line += word;
  297. length += whitelgth + worldlgth;
  298. }
  299. word = L"";
  300. whitespace = L"";
  301. if (c)
  302. whitespace += c;
  303. // compute line break
  304. if (line_break) {
  305. line += whitespace;
  306. line += word;
  307. m_broken_text.push_back(line);
  308. m_broken_text_positions.push_back(last_line_start);
  309. last_line_start = i + 1;
  310. line = L"";
  311. word = L"";
  312. whitespace = L"";
  313. length = 0;
  314. }
  315. } else {
  316. // yippee this is a word..
  317. word += c;
  318. }
  319. }
  320. line += whitespace;
  321. line += word;
  322. m_broken_text.push_back(line);
  323. m_broken_text_positions.push_back(last_line_start);
  324. }
  325. // TODO: that function does interpret VAlign according to line-index (indexed
  326. // line is placed on top-center-bottom) but HAlign according to line-width
  327. // (pixels) and not by row.
  328. // Intuitively I suppose HAlign handling is better as VScrollPos should handle
  329. // the line-scrolling.
  330. // But please no one change this without also rewriting (and this time
  331. // testing!!!) autoscrolling (I noticed this when fixing the old autoscrolling).
  332. void GUIEditBoxWithScrollBar::setTextRect(s32 line)
  333. {
  334. if (line < 0)
  335. return;
  336. IGUIFont* font = getActiveFont();
  337. if (!font)
  338. return;
  339. core::dimension2du d;
  340. // get text dimension
  341. const u32 line_count = (m_word_wrap || m_multiline) ? m_broken_text.size() : 1;
  342. if (m_word_wrap || m_multiline) {
  343. d = font->getDimension(m_broken_text[line].c_str());
  344. } else {
  345. d = font->getDimension(Text.c_str());
  346. d.Height = AbsoluteRect.getHeight();
  347. }
  348. d.Height += font->getKerningHeight();
  349. // justification
  350. switch (m_halign) {
  351. case EGUIA_CENTER:
  352. // align to h center
  353. m_current_text_rect.UpperLeftCorner.X = (m_frame_rect.getWidth() / 2) - (d.Width / 2);
  354. m_current_text_rect.LowerRightCorner.X = (m_frame_rect.getWidth() / 2) + (d.Width / 2);
  355. break;
  356. case EGUIA_LOWERRIGHT:
  357. // align to right edge
  358. m_current_text_rect.UpperLeftCorner.X = m_frame_rect.getWidth() - d.Width;
  359. m_current_text_rect.LowerRightCorner.X = m_frame_rect.getWidth();
  360. break;
  361. default:
  362. // align to left edge
  363. m_current_text_rect.UpperLeftCorner.X = 0;
  364. m_current_text_rect.LowerRightCorner.X = d.Width;
  365. }
  366. switch (m_valign) {
  367. case EGUIA_CENTER:
  368. // align to v center
  369. m_current_text_rect.UpperLeftCorner.Y =
  370. (m_frame_rect.getHeight() / 2) - (line_count*d.Height) / 2 + d.Height*line;
  371. break;
  372. case EGUIA_LOWERRIGHT:
  373. // align to bottom edge
  374. m_current_text_rect.UpperLeftCorner.Y =
  375. m_frame_rect.getHeight() - line_count*d.Height + d.Height*line;
  376. break;
  377. default:
  378. // align to top edge
  379. m_current_text_rect.UpperLeftCorner.Y = d.Height*line;
  380. break;
  381. }
  382. m_current_text_rect.UpperLeftCorner.X -= m_hscroll_pos;
  383. m_current_text_rect.LowerRightCorner.X -= m_hscroll_pos;
  384. m_current_text_rect.UpperLeftCorner.Y -= m_vscroll_pos;
  385. m_current_text_rect.LowerRightCorner.Y = m_current_text_rect.UpperLeftCorner.Y + d.Height;
  386. m_current_text_rect += m_frame_rect.UpperLeftCorner;
  387. }
  388. // calculate autoscroll
  389. void GUIEditBoxWithScrollBar::calculateScrollPos()
  390. {
  391. if (!m_autoscroll)
  392. return;
  393. IGUISkin* skin = Environment->getSkin();
  394. if (!skin)
  395. return;
  396. IGUIFont* font = m_override_font ? m_override_font : skin->getFont();
  397. if (!font)
  398. return;
  399. s32 curs_line = getLineFromPos(m_cursor_pos);
  400. if (curs_line < 0)
  401. return;
  402. setTextRect(curs_line);
  403. const bool has_broken_text = m_multiline || m_word_wrap;
  404. // Check horizonal scrolling
  405. // NOTE: Calculations different to vertical scrolling because setTextRect interprets VAlign relative to line but HAlign not relative to row
  406. {
  407. // get cursor position
  408. IGUIFont* font = getActiveFont();
  409. if (!font)
  410. return;
  411. // get cursor area
  412. irr::u32 cursor_width = font->getDimension(L"_").Width;
  413. core::stringw *txt_line = has_broken_text ? &m_broken_text[curs_line] : &Text;
  414. s32 cpos = has_broken_text ? m_cursor_pos - m_broken_text_positions[curs_line] : m_cursor_pos; // column
  415. s32 cstart = font->getDimension(txt_line->subString(0, cpos).c_str()).Width; // pixels from text-start
  416. s32 cend = cstart + cursor_width;
  417. s32 txt_width = font->getDimension(txt_line->c_str()).Width;
  418. if (txt_width < m_frame_rect.getWidth()) {
  419. // TODO: Needs a clean left and right gap removal depending on HAlign, similar to vertical scrolling tests for top/bottom.
  420. // This check just fixes the case where it was most noticeable (text smaller than clipping area).
  421. m_hscroll_pos = 0;
  422. setTextRect(curs_line);
  423. }
  424. if (m_current_text_rect.UpperLeftCorner.X + cstart < m_frame_rect.UpperLeftCorner.X) {
  425. // cursor to the left of the clipping area
  426. m_hscroll_pos -= m_frame_rect.UpperLeftCorner.X - (m_current_text_rect.UpperLeftCorner.X + cstart);
  427. setTextRect(curs_line);
  428. // TODO: should show more characters to the left when we're scrolling left
  429. // and the cursor reaches the border.
  430. } else if (m_current_text_rect.UpperLeftCorner.X + cend > m_frame_rect.LowerRightCorner.X) {
  431. // cursor to the right of the clipping area
  432. m_hscroll_pos += (m_current_text_rect.UpperLeftCorner.X + cend) - m_frame_rect.LowerRightCorner.X;
  433. setTextRect(curs_line);
  434. }
  435. }
  436. // calculate vertical scrolling
  437. if (has_broken_text) {
  438. irr::u32 line_height = font->getDimension(L"A").Height + font->getKerningHeight();
  439. // only up to 1 line fits?
  440. if (line_height >= (irr::u32)m_frame_rect.getHeight()) {
  441. m_vscroll_pos = 0;
  442. setTextRect(curs_line);
  443. s32 unscrolledPos = m_current_text_rect.UpperLeftCorner.Y;
  444. s32 pivot = m_frame_rect.UpperLeftCorner.Y;
  445. switch (m_valign) {
  446. case EGUIA_CENTER:
  447. pivot += m_frame_rect.getHeight() / 2;
  448. unscrolledPos += line_height / 2;
  449. break;
  450. case EGUIA_LOWERRIGHT:
  451. pivot += m_frame_rect.getHeight();
  452. unscrolledPos += line_height;
  453. break;
  454. default:
  455. break;
  456. }
  457. m_vscroll_pos = unscrolledPos - pivot;
  458. setTextRect(curs_line);
  459. } else {
  460. // First 2 checks are necessary when people delete lines
  461. setTextRect(0);
  462. if (m_current_text_rect.UpperLeftCorner.Y > m_frame_rect.UpperLeftCorner.Y && m_valign != EGUIA_LOWERRIGHT) {
  463. // first line is leaving a gap on top
  464. m_vscroll_pos = 0;
  465. } else if (m_valign != EGUIA_UPPERLEFT) {
  466. u32 lastLine = m_broken_text_positions.empty() ? 0 : m_broken_text_positions.size() - 1;
  467. setTextRect(lastLine);
  468. if (m_current_text_rect.LowerRightCorner.Y < m_frame_rect.LowerRightCorner.Y)
  469. {
  470. // last line is leaving a gap on bottom
  471. m_vscroll_pos -= m_frame_rect.LowerRightCorner.Y - m_current_text_rect.LowerRightCorner.Y;
  472. }
  473. }
  474. setTextRect(curs_line);
  475. if (m_current_text_rect.UpperLeftCorner.Y < m_frame_rect.UpperLeftCorner.Y) {
  476. // text above valid area
  477. m_vscroll_pos -= m_frame_rect.UpperLeftCorner.Y - m_current_text_rect.UpperLeftCorner.Y;
  478. setTextRect(curs_line);
  479. } else if (m_current_text_rect.LowerRightCorner.Y > m_frame_rect.LowerRightCorner.Y){
  480. // text below valid area
  481. m_vscroll_pos += m_current_text_rect.LowerRightCorner.Y - m_frame_rect.LowerRightCorner.Y;
  482. setTextRect(curs_line);
  483. }
  484. }
  485. }
  486. if (m_vscrollbar) {
  487. m_vscrollbar->setPos(m_vscroll_pos);
  488. }
  489. }
  490. void GUIEditBoxWithScrollBar::calculateFrameRect()
  491. {
  492. m_frame_rect = AbsoluteRect;
  493. IGUISkin *skin = 0;
  494. if (Environment)
  495. skin = Environment->getSkin();
  496. if (m_border && skin) {
  497. m_frame_rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X) + 1;
  498. m_frame_rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1;
  499. m_frame_rect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X) + 1;
  500. m_frame_rect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1;
  501. }
  502. updateVScrollBar();
  503. }
  504. //! create a vertical scroll bar
  505. void GUIEditBoxWithScrollBar::createVScrollBar()
  506. {
  507. IGUISkin *skin = 0;
  508. if (Environment)
  509. skin = Environment->getSkin();
  510. s32 fontHeight = 1;
  511. if (m_override_font) {
  512. fontHeight = m_override_font->getDimension(L"Ay").Height;
  513. } else {
  514. IGUIFont *font;
  515. if (skin && (font = skin->getFont())) {
  516. fontHeight = font->getDimension(L"Ay").Height;
  517. }
  518. }
  519. m_scrollbar_width = skin ? skin->getSize(gui::EGDS_SCROLLBAR_SIZE) : 16;
  520. irr::core::rect<s32> scrollbarrect = m_frame_rect;
  521. scrollbarrect.UpperLeftCorner.X += m_frame_rect.getWidth() - m_scrollbar_width;
  522. m_vscrollbar = new GUIScrollBar(Environment, getParent(), -1,
  523. scrollbarrect, false, true, m_tsrc);
  524. m_vscrollbar->setVisible(false);
  525. m_vscrollbar->setSmallStep(3 * fontHeight);
  526. m_vscrollbar->setLargeStep(10 * fontHeight);
  527. }
  528. //! Change the background color
  529. void GUIEditBoxWithScrollBar::setBackgroundColor(const video::SColor &bg_color)
  530. {
  531. m_bg_color = bg_color;
  532. m_bg_color_used = true;
  533. }
  534. bool GUIEditBoxWithScrollBar::isDrawBackgroundEnabled() const { return false; }
  535. bool GUIEditBoxWithScrollBar::isDrawBorderEnabled() const { return false; }
  536. void GUIEditBoxWithScrollBar::setCursorChar(const wchar_t cursorChar) { }
  537. wchar_t GUIEditBoxWithScrollBar::getCursorChar() const { return '|'; }
  538. void GUIEditBoxWithScrollBar::setCursorBlinkTime(irr::u32 timeMs) { }
  539. irr::u32 GUIEditBoxWithScrollBar::getCursorBlinkTime() const { return 500; }