GUIBase.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. #include "SDL_Extensions.h"
  2. #include <cassert>
  3. #include <boost/thread/locks.hpp>
  4. #include "GUIBase.h"
  5. #include <boost/thread/mutex.hpp>
  6. #include <queue>
  7. #include "CGameInfo.h"
  8. #include "CCursorHandler.h"
  9. #include "CBitmapHandler.h"
  10. /*
  11. * GUIBase.cpp, part of VCMI engine
  12. *
  13. * Authors: listed in file AUTHORS in main folder
  14. *
  15. * License: GNU General Public License v2.0 or later
  16. * Full text of license available in license.txt file, in main folder
  17. *
  18. */
  19. extern std::queue<SDL_Event*> events;
  20. extern boost::mutex eventsM;
  21. void KeyShortcut::keyPressed(const SDL_KeyboardEvent & key)
  22. {
  23. if(vstd::contains(assignedKeys,key.keysym.sym))
  24. {
  25. bool prev = pressedL;
  26. if(key.state == SDL_PRESSED)
  27. {
  28. pressedL = true;
  29. clickLeft(true, prev);
  30. } else
  31. {
  32. pressedL = false;
  33. clickLeft(false, prev);
  34. }
  35. }
  36. }
  37. void CGuiHandler::popInt( IShowActivable *top )
  38. {
  39. assert(listInt.front() == top);
  40. top->deactivate();
  41. listInt.pop_front();
  42. objsToBlit -= top;
  43. if(listInt.size())
  44. listInt.front()->activate();
  45. totalRedraw();
  46. }
  47. void CGuiHandler::popIntTotally( IShowActivable *top )
  48. {
  49. assert(listInt.front() == top);
  50. popInt(top);
  51. delete top;
  52. }
  53. void CGuiHandler::pushInt( IShowActivable *newInt )
  54. {
  55. //a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
  56. screenBuf = screen2;
  57. if(listInt.size())
  58. listInt.front()->deactivate();
  59. listInt.push_front(newInt);
  60. newInt->activate();
  61. objsToBlit.push_back(newInt);
  62. totalRedraw();
  63. }
  64. void CGuiHandler::popInts( int howMany )
  65. {
  66. if(!howMany) return; //senseless but who knows...
  67. assert(listInt.size() > howMany);
  68. listInt.front()->deactivate();
  69. for(int i=0; i < howMany; i++)
  70. {
  71. objsToBlit -= listInt.front();
  72. delete listInt.front();
  73. listInt.pop_front();
  74. }
  75. listInt.front()->activate();
  76. totalRedraw();
  77. }
  78. IShowActivable * CGuiHandler::topInt()
  79. {
  80. if(!listInt.size())
  81. return NULL;
  82. else
  83. return listInt.front();
  84. }
  85. void CGuiHandler::totalRedraw()
  86. {
  87. for(int i=0;i<objsToBlit.size();i++)
  88. objsToBlit[i]->showAll(screen2);
  89. blitAt(screen2,0,0,screen);
  90. if(objsToBlit.size())
  91. objsToBlit.back()->showAll(screen);
  92. }
  93. void CGuiHandler::updateTime()
  94. {
  95. int tv = th.getDif();
  96. std::list<CIntObject*> hlp = timeinterested;
  97. for (std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
  98. {
  99. if(!vstd::contains(timeinterested,*i)) continue;
  100. if ((*i)->toNextTick>=0)
  101. (*i)->toNextTick-=tv;
  102. if ((*i)->toNextTick<0)
  103. (*i)->tick();
  104. }
  105. }
  106. void CGuiHandler::handleEvents()
  107. {
  108. while(true)
  109. {
  110. SDL_Event *ev = NULL;
  111. {
  112. boost::unique_lock<boost::mutex> lock(eventsM);
  113. if(!events.size())
  114. {
  115. return;
  116. }
  117. else
  118. {
  119. ev = events.front();
  120. events.pop();
  121. }
  122. }
  123. handleEvent(ev);
  124. delete ev;
  125. }
  126. }
  127. void CGuiHandler::handleEvent(SDL_Event *sEvent)
  128. {
  129. current = sEvent;
  130. bool prev;
  131. if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP)
  132. {
  133. SDL_KeyboardEvent key = sEvent->key;
  134. //translate numpad keys
  135. if(key.keysym.sym == SDLK_KP_ENTER)
  136. {
  137. key.keysym.sym = (SDLKey)SDLK_RETURN;
  138. }
  139. bool keysCaptured = false;
  140. for(std::list<CIntObject*>::iterator i=keyinterested.begin(); i != keyinterested.end();i++)
  141. {
  142. if((*i)->captureAllKeys)
  143. {
  144. keysCaptured = true;
  145. break;
  146. }
  147. }
  148. std::list<CIntObject*> miCopy = keyinterested;
  149. for(std::list<CIntObject*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
  150. if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureAllKeys))
  151. (**i).keyPressed(key);
  152. }
  153. else if(sEvent->type==SDL_MOUSEMOTION)
  154. {
  155. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  156. handleMouseMotion(sEvent);
  157. }
  158. else if (sEvent->type==SDL_MOUSEBUTTONDOWN)
  159. {
  160. if(sEvent->button.button == SDL_BUTTON_LEFT)
  161. {
  162. if(lastClick == sEvent->motion && (SDL_GetTicks() - lastClickTime) < 300)
  163. {
  164. std::list<CIntObject*> hlp = doubleClickInterested;
  165. for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
  166. {
  167. if(!vstd::contains(doubleClickInterested,*i)) continue;
  168. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  169. {
  170. (*i)->onDoubleClick();
  171. }
  172. }
  173. }
  174. lastClick = sEvent->motion;
  175. lastClickTime = SDL_GetTicks();
  176. std::list<CIntObject*> hlp = lclickable;
  177. for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
  178. {
  179. if(!vstd::contains(lclickable,*i)) continue;
  180. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  181. {
  182. prev = (*i)->pressedL;
  183. (*i)->pressedL = true;
  184. (*i)->clickLeft(true, prev);
  185. }
  186. }
  187. }
  188. else if (sEvent->button.button == SDL_BUTTON_RIGHT)
  189. {
  190. std::list<CIntObject*> hlp = rclickable;
  191. for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
  192. {
  193. if(!vstd::contains(rclickable,*i)) continue;
  194. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  195. {
  196. prev = (*i)->pressedR;
  197. (*i)->pressedR = true;
  198. (*i)->clickRight(true, prev);
  199. }
  200. }
  201. }
  202. else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP)
  203. {
  204. std::list<CIntObject*> hlp = wheelInterested;
  205. for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
  206. {
  207. if(!vstd::contains(wheelInterested,*i)) continue;
  208. (*i)->wheelScrolled(sEvent->button.button == SDL_BUTTON_WHEELDOWN, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y));
  209. }
  210. }
  211. }
  212. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  213. {
  214. std::list<CIntObject*> hlp = lclickable;
  215. for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
  216. {
  217. if(!vstd::contains(lclickable,*i)) continue;
  218. prev = (*i)->pressedL;
  219. (*i)->pressedL = false;
  220. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  221. {
  222. (*i)->clickLeft(false, prev);
  223. }
  224. else
  225. (*i)->clickLeft(boost::logic::indeterminate, prev);
  226. }
  227. }
  228. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  229. {
  230. std::list<CIntObject*> hlp = rclickable;
  231. for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
  232. {
  233. if(!vstd::contains(rclickable,*i)) continue;
  234. prev = (*i)->pressedR;
  235. (*i)->pressedR = false;
  236. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  237. {
  238. (*i)->clickRight(false, prev);
  239. }
  240. else
  241. (*i)->clickRight(boost::logic::indeterminate, prev);
  242. }
  243. }
  244. current = NULL;
  245. } //event end
  246. void CGuiHandler::handleMouseMotion(SDL_Event *sEvent)
  247. {
  248. //sending active, hovered hoverable objects hover() call
  249. std::vector<CIntObject*> hlp;
  250. for(std::list<CIntObject*>::iterator i=hoverable.begin(); i != hoverable.end();i++)
  251. {
  252. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  253. {
  254. if (!(*i)->hovered)
  255. hlp.push_back((*i));
  256. }
  257. else if ((*i)->hovered)
  258. {
  259. (*i)->hover(false);
  260. (*i)->hovered = false;
  261. }
  262. }
  263. for(int i=0; i<hlp.size();i++)
  264. {
  265. hlp[i]->hover(true);
  266. hlp[i]->hovered = true;
  267. }
  268. //sending active, MotionInterested objects mouseMoved() call
  269. std::list<CIntObject*> miCopy = motioninterested;
  270. for(std::list<CIntObject*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
  271. {
  272. if ((*i)->strongInterest || isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  273. {
  274. (*i)->mouseMoved(sEvent->motion);
  275. }
  276. }
  277. }
  278. void CGuiHandler::simpleRedraw()
  279. {
  280. //update only top interface and draw background
  281. if(objsToBlit.size() > 1)
  282. blitAt(screen2,0,0,screen); //blit background
  283. objsToBlit.back()->show(screen); //blit active interface/window
  284. }
  285. void CIntObject::activateLClick()
  286. {
  287. GH.lclickable.push_front(this);
  288. active |= LCLICK;
  289. }
  290. void CIntObject::deactivateLClick()
  291. {
  292. std::list<CIntObject*>::iterator hlp = std::find(GH.lclickable.begin(),GH.lclickable.end(),this);
  293. assert(hlp != GH.lclickable.end());
  294. GH.lclickable.erase(hlp);
  295. active &= ~LCLICK;
  296. }
  297. void CIntObject::clickLeft(tribool down, bool previousState)
  298. {
  299. }
  300. void CIntObject::activateRClick()
  301. {
  302. GH.rclickable.push_front(this);
  303. active |= RCLICK;
  304. }
  305. void CIntObject::deactivateRClick()
  306. {
  307. std::list<CIntObject*>::iterator hlp = std::find(GH.rclickable.begin(),GH.rclickable.end(),this);
  308. assert(hlp != GH.rclickable.end());
  309. GH.rclickable.erase(hlp);
  310. active &= ~RCLICK;
  311. }
  312. void CIntObject::clickRight(tribool down, bool previousState)
  313. {
  314. }
  315. void CIntObject::activateHover()
  316. {
  317. GH.hoverable.push_front(this);
  318. active |= HOVER;
  319. }
  320. void CIntObject::deactivateHover()
  321. {
  322. std::list<CIntObject*>::iterator hlp = std::find(GH.hoverable.begin(),GH.hoverable.end(),this);
  323. assert(hlp != GH.hoverable.end());
  324. GH.hoverable.erase(hlp);
  325. active &= ~HOVER;
  326. }
  327. void CIntObject::hover( bool on )
  328. {
  329. }
  330. void CIntObject::activateKeys()
  331. {
  332. GH.keyinterested.push_front(this);
  333. active |= KEYBOARD;
  334. }
  335. void CIntObject::deactivateKeys()
  336. {
  337. std::list<CIntObject*>::iterator hlp = std::find(GH.keyinterested.begin(),GH.keyinterested.end(),this);
  338. assert(hlp != GH.keyinterested.end());
  339. GH.keyinterested.erase(hlp);
  340. active &= ~KEYBOARD;
  341. }
  342. void CIntObject::keyPressed( const SDL_KeyboardEvent & key )
  343. {
  344. }
  345. void CIntObject::activateMouseMove()
  346. {
  347. GH.motioninterested.push_front(this);
  348. active |= MOVE;
  349. }
  350. void CIntObject::deactivateMouseMove()
  351. {
  352. std::list<CIntObject*>::iterator hlp = std::find(GH.motioninterested.begin(),GH.motioninterested.end(),this);
  353. assert(hlp != GH.motioninterested.end());
  354. GH.motioninterested.erase(hlp);
  355. active &= ~MOVE;
  356. }
  357. void CIntObject::mouseMoved( const SDL_MouseMotionEvent & sEvent )
  358. {
  359. }
  360. void CIntObject::activateTimer()
  361. {
  362. GH.timeinterested.push_back(this);
  363. active |= TIME;
  364. }
  365. void CIntObject::deactivateTimer()
  366. {
  367. std::list<CIntObject*>::iterator hlp = std::find(GH.timeinterested.begin(),GH.timeinterested.end(),this);
  368. assert(hlp != GH.timeinterested.end());
  369. GH.timeinterested.erase(hlp);
  370. active &= ~TIME;
  371. }
  372. void CIntObject::tick()
  373. {
  374. }
  375. CIntObject::CIntObject()
  376. {
  377. pressedL = pressedR = hovered = captureAllKeys = strongInterest = toNextTick = active = used = 0;
  378. recActions = defActions = GH.defActionsDef;
  379. pos.x = 0;
  380. pos.y = 0;
  381. pos.w = 0;
  382. pos.h = 0;
  383. if(GH.captureChildren)
  384. {
  385. assert(GH.createdObj.size());
  386. parent = GH.createdObj.front();
  387. parent->children.push_back(this);
  388. if(parent->defActions & SHARE_POS)
  389. {
  390. pos.x = parent->pos.x;
  391. pos.y = parent->pos.y;
  392. }
  393. }
  394. }
  395. void CIntObject::show( SDL_Surface * to )
  396. {
  397. if(defActions & UPDATE)
  398. for(size_t i = 0; i < children.size(); i++)
  399. if(children[i]->recActions & UPDATE)
  400. children[i]->show(to);
  401. }
  402. void CIntObject::showAll( SDL_Surface * to )
  403. {
  404. if(defActions & SHOWALL)
  405. {
  406. for(size_t i = 0; i < children.size(); i++)
  407. if(children[i]->recActions & SHOWALL)
  408. children[i]->showAll(to);
  409. }
  410. else
  411. show(to);
  412. }
  413. void CIntObject::activate()
  414. {
  415. assert(!active);
  416. active |= GENERAL;
  417. if(used & LCLICK)
  418. activateLClick();
  419. if(used & RCLICK)
  420. activateRClick();
  421. if(used & HOVER)
  422. activateHover();
  423. if(used & MOVE)
  424. activateMouseMove();
  425. if(used & KEYBOARD)
  426. activateKeys();
  427. if(used & TIME)
  428. activateTimer();
  429. if(used & WHEEL)
  430. activateWheel();
  431. if(used & DOUBLECLICK)
  432. activateDClick();
  433. if(defActions & ACTIVATE)
  434. for(size_t i = 0; i < children.size(); i++)
  435. if(children[i]->recActions & ACTIVATE)
  436. children[i]->activate();
  437. }
  438. void CIntObject::deactivate()
  439. {
  440. assert(active);
  441. active &= ~ GENERAL;
  442. if(used & LCLICK)
  443. deactivateLClick();
  444. if(used & RCLICK)
  445. deactivateRClick();
  446. if(used & HOVER)
  447. deactivateHover();
  448. if(used & MOVE)
  449. deactivateMouseMove();
  450. if(used & KEYBOARD)
  451. deactivateKeys();
  452. if(used & TIME)
  453. deactivateTimer();
  454. if(used & WHEEL)
  455. deactivateWheel();
  456. if(used & DOUBLECLICK)
  457. deactivateDClick();
  458. if(defActions & DEACTIVATE)
  459. for(size_t i = 0; i < children.size(); i++)
  460. if(children[i]->recActions & DEACTIVATE)
  461. children[i]->deactivate();
  462. }
  463. CIntObject::~CIntObject()
  464. {
  465. assert(!active); //do not delete active obj
  466. if(defActions & DISPOSE)
  467. for(size_t i = 0; i < children.size(); i++)
  468. if(children[i]->recActions & DISPOSE)
  469. delete children[i];
  470. }
  471. void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/, bool refresh /*= false*/ )
  472. {
  473. CSDL_Ext::printAt(text, pos.x + x, pos.y + y, font, kolor, dst, refresh);
  474. }
  475. void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/, bool refresh /*= false*/ )
  476. {
  477. CSDL_Ext::printAtMiddle(text, pos.x + x, pos.y + y, font, kolor, dst, refresh);
  478. }
  479. void CIntObject::blitAtLoc( SDL_Surface * src, int x, int y, SDL_Surface * dst )
  480. {
  481. blitAt(src, pos.x + x, pos.y + y, dst);
  482. }
  483. void CIntObject::printAtMiddleWBLoc( const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor, SDL_Surface * dst, bool refrsh /*= false*/ )
  484. {
  485. CSDL_Ext::printAtMiddleWB(text, pos.x + x, pos.y + y, font, charpr, kolor, dst, refrsh);
  486. }
  487. void CIntObject::printToLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst, bool refresh /*= false*/ )
  488. {
  489. CSDL_Ext::printTo(text, pos.x + x, pos.y + y, font, kolor, dst, refresh);
  490. }
  491. void CIntObject::disable()
  492. {
  493. if(active)
  494. deactivate();
  495. recActions = DISPOSE;
  496. }
  497. void CIntObject::enable(bool activation)
  498. {
  499. if(!active && activation)
  500. activate();
  501. recActions = 255;
  502. }
  503. bool CIntObject::isItInLoc( const SDL_Rect &rect, int x, int y )
  504. {
  505. return isItIn(&rect, x - pos.x, y - pos.y);
  506. }
  507. bool CIntObject::isItInLoc( const SDL_Rect &rect, const Point &p )
  508. {
  509. return isItIn(&rect, p.x - pos.x, p.y - pos.y);
  510. }
  511. void CIntObject::activateWheel()
  512. {
  513. GH.wheelInterested.push_front(this);
  514. active |= WHEEL;
  515. }
  516. void CIntObject::deactivateWheel()
  517. {
  518. std::list<CIntObject*>::iterator hlp = std::find(GH.wheelInterested.begin(),GH.wheelInterested.end(),this);
  519. assert(hlp != GH.wheelInterested.end());
  520. GH.wheelInterested.erase(hlp);
  521. active &= ~WHEEL;
  522. }
  523. void CIntObject::wheelScrolled(bool down, bool in)
  524. {
  525. }
  526. void CIntObject::activateDClick()
  527. {
  528. GH.doubleClickInterested.push_front(this);
  529. active |= DOUBLECLICK;
  530. }
  531. void CIntObject::deactivateDClick()
  532. {
  533. std::list<CIntObject*>::iterator hlp = std::find(GH.doubleClickInterested.begin(),GH.doubleClickInterested.end(),this);
  534. assert(hlp != GH.doubleClickInterested.end());
  535. GH.doubleClickInterested.erase(hlp);
  536. active &= ~DOUBLECLICK;
  537. }
  538. void CIntObject::onDoubleClick()
  539. {
  540. }
  541. const Rect & CIntObject::center( const Rect &r )
  542. {
  543. pos.w = r.w;
  544. pos.h = r.h;
  545. pos.x = screen->w/2 - r.w/2;
  546. pos.y = screen->h/2 - r.h/2;
  547. return pos;
  548. }
  549. const Rect & CIntObject::center()
  550. {
  551. return center(pos);
  552. }
  553. CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free )
  554. {
  555. bg = BG;
  556. freeSurf = Free;
  557. pos.x += x;
  558. pos.y += y;
  559. pos.w = BG->w;
  560. pos.h = BG->h;
  561. }
  562. CPicture::CPicture( const std::string &bmpname, int x, int y )
  563. {
  564. bg = BitmapHandler::loadBitmap(bmpname);
  565. freeSurf = true;;
  566. pos.x += x;
  567. pos.y += y;
  568. pos.w = bg->w;
  569. pos.h = bg->h;
  570. }
  571. CPicture::~CPicture()
  572. {
  573. if(freeSurf)
  574. SDL_FreeSurface(bg);
  575. }
  576. void CPicture::showAll( SDL_Surface * to )
  577. {
  578. blitAt(bg, pos, to);
  579. }
  580. ObjectConstruction::ObjectConstruction( CIntObject *obj )
  581. :myObj(obj)
  582. {
  583. GH.createdObj.push_front(obj);
  584. GH.captureChildren = true;
  585. }
  586. ObjectConstruction::~ObjectConstruction()
  587. {
  588. assert(GH.createdObj.size());
  589. assert(GH.createdObj.front() == myObj);
  590. GH.createdObj.pop_front();
  591. GH.captureChildren = GH.createdObj.size();
  592. }
  593. SetCaptureState::SetCaptureState(bool allow, ui8 actions)
  594. {
  595. previousCapture = GH.captureChildren;
  596. GH.captureChildren = false;
  597. prevActions = GH.defActionsDef;
  598. GH.defActionsDef = actions;
  599. }
  600. SetCaptureState::~SetCaptureState()
  601. {
  602. GH.captureChildren = previousCapture;
  603. GH.defActionsDef = prevActions;
  604. }
  605. void IShowable::redraw()
  606. {
  607. showAll(screenBuf);
  608. if(screenBuf != screen)
  609. showAll(screen);
  610. }
  611. SDLKey arrowToNum( SDLKey key )
  612. {
  613. switch(key)
  614. {
  615. case SDLK_DOWN:
  616. return SDLK_KP2;
  617. case SDLK_UP:
  618. return SDLK_KP8;
  619. case SDLK_LEFT:
  620. return SDLK_KP4;
  621. case SDLK_RIGHT:
  622. return SDLK_KP6;
  623. default:
  624. assert(0);
  625. }
  626. throw std::string("Wrong key!");
  627. }
  628. SDLKey numToDigit( SDLKey key )
  629. {
  630. return SDLKey(key - SDLK_KP0 + SDLK_0);
  631. }
  632. bool isNumKey( SDLKey key, bool number )
  633. {
  634. if(number)
  635. return key >= SDLK_KP0 && key <= SDLK_KP_EQUALS;
  636. else
  637. return key >= SDLK_KP0 && key <= SDLK_KP9;
  638. }
  639. bool isArrowKey( SDLKey key )
  640. {
  641. return key >= SDLK_UP && key <= SDLK_LEFT;
  642. }