AdventureMapButton.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. #include "AdventureMapButton.h"
  2. #include "CAdvmapInterface.h"
  3. #include "SDL_Extensions.h"
  4. #include "../hch/CDefHandler.h"
  5. #include "CGameInfo.h"
  6. #include "../hch/CLodHandler.h"
  7. #include "../hch/CGeneralTextHandler.h"
  8. #include "../hch/CTownHandler.h"
  9. #include "../CCallback.h"
  10. #include "CConfigHandler.h"
  11. #include "Graphics.h"
  12. #include "CBattleInterface.h"
  13. #include "CPlayerInterface.h"
  14. #include "CMessage.h"
  15. /*
  16. * AdevntureMapButton.cpp, part of VCMI engine
  17. *
  18. * Authors: listed in file AUTHORS in main folder
  19. *
  20. * License: GNU General Public License v2.0 or later
  21. * Full text of license available in license.txt file, in main folder
  22. *
  23. */
  24. CButtonBase::CButtonBase()
  25. {
  26. bitmapOffset = 0;
  27. curimg=0;
  28. type=-1;
  29. abs=false;
  30. //active=false;
  31. notFreeButton = false;
  32. ourObj=NULL;
  33. state=0;
  34. text = NULL;
  35. }
  36. CButtonBase::~CButtonBase()
  37. {
  38. delete text;
  39. if(notFreeButton)
  40. return;
  41. for(int i =0; i<imgs.size();i++)
  42. for(int j=0;j<imgs[i].size();j++)
  43. SDL_FreeSurface(imgs[i][j]);
  44. }
  45. void CButtonBase::show(SDL_Surface * to)
  46. {
  47. int img = std::min(state+bitmapOffset,int(imgs[curimg].size()-1));
  48. img = std::max(0, img);
  49. if (abs)
  50. {
  51. blitAt(imgs[curimg][img],pos.x,pos.y,to);
  52. if(text)
  53. {//using "state" instead of "state == 1" screwed up hoverable buttons with text
  54. CSDL_Ext::printAt(text->text, text->x + pos.x + (state == 1), text->y + pos.y + (state == 1), text->font, text->color, to);
  55. }
  56. }
  57. else
  58. {
  59. blitAt(imgs[curimg][img],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
  60. }
  61. }
  62. void CButtonBase::showAll( SDL_Surface * to )
  63. {
  64. show(to);
  65. }
  66. void CButtonBase::addTextOverlay( const std::string Text, EFonts font, SDL_Color color)
  67. {
  68. delete text;
  69. text = new TextOverlay;
  70. text->text = Text;
  71. const Font *f = graphics->fonts[font];
  72. text->x = pos.w/2 - f->getWidth(Text.c_str())/2;
  73. text->y = pos.h/2 - f->height/2;
  74. text->font = font;
  75. text->color = color;
  76. }
  77. AdventureMapButton::AdventureMapButton ()
  78. {
  79. type=2;
  80. abs=true;
  81. hoverable = false;
  82. //active=false;
  83. ourObj=NULL;
  84. state=0;
  85. blocked = actOnDown = false;
  86. used = LCLICK | RCLICK | HOVER | KEYBOARD;
  87. }
  88. //AdventureMapButton::AdventureMapButton( std::string Name, std::string HelpBox, boost::function<void()> Callback, int x, int y, std::string defName, bool activ, std::vector<std::string> * add, bool playerColoredButton)
  89. //{
  90. // init(Callback, Name, HelpBox, playerColoredButton, defName, add, x, y, activ);
  91. //}
  92. AdventureMapButton::AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName,int key, std::vector<std::string> * add, bool playerColoredButton )
  93. {
  94. std::map<int,std::string> pom;
  95. pom[0] = Name;
  96. init(Callback, pom, HelpBox, playerColoredButton, defName, add, x, y, key);
  97. }
  98. AdventureMapButton::AdventureMapButton( const std::map<int,std::string> &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key, std::vector<std::string> * add /*= NULL*/, bool playerColoredButton /*= false */ )
  99. {
  100. init(Callback, Name, HelpBox, playerColoredButton, defName, add, x, y, key);
  101. }
  102. AdventureMapButton::AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, config::ButtonInfo *info, int key/*=0*/ )
  103. {
  104. std::map<int,std::string> pom;
  105. pom[0] = Name;
  106. init(Callback, pom, HelpBox, info->playerColoured, info->defName, &info->additionalDefs, info->x, info->y, key);
  107. }
  108. AdventureMapButton::AdventureMapButton( const std::pair<std::string, std::string> help, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key/*=0*/, std::vector<std::string> * add /*= NULL*/, bool playerColoredButton /*= false */ )
  109. {
  110. std::map<int,std::string> pom;
  111. pom[0] = help.first;
  112. init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key);
  113. }
  114. void AdventureMapButton::clickLeft(tribool down, bool previousState)
  115. {
  116. if(blocked)
  117. return;
  118. if (down)
  119. {
  120. CGI->soundh->playSound(soundBase::button);
  121. state = 1;
  122. }
  123. else if(hoverable && hovered)
  124. state = 3;
  125. else
  126. state = 0;
  127. show(screenBuf);
  128. if (actOnDown && down)
  129. {
  130. callback();
  131. }
  132. else if (!actOnDown && previousState && (down==false))
  133. {
  134. callback();
  135. }
  136. }
  137. void AdventureMapButton::clickRight(tribool down, bool previousState)
  138. {
  139. if(down && helpBox.size()) //there is no point to show window with nothing inside...
  140. CRClickPopup::createAndPush(helpBox);
  141. }
  142. void AdventureMapButton::hover (bool on)
  143. {
  144. if(hoverable)
  145. {
  146. if(on)
  147. state = 3;
  148. else
  149. state = 0;
  150. }
  151. if(pressedL)
  152. {
  153. if(on)
  154. state = 1;
  155. else
  156. state = hoverable ? 3 : 0;
  157. }
  158. ////Hoverable::hover(on);
  159. std::string *name = (vstd::contains(hoverTexts,state))
  160. ? (&hoverTexts[state])
  161. : (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL);
  162. if(name && name->size() && blocked!=1) //if there is no name, there is nohing to display also
  163. {
  164. if (LOCPLINT && LOCPLINT->battleInt) //for battle buttons
  165. {
  166. if(on && LOCPLINT->battleInt->console->alterTxt == "")
  167. {
  168. LOCPLINT->battleInt->console->alterTxt = *name;
  169. LOCPLINT->battleInt->console->whoSetAlter = 1;
  170. }
  171. else if (LOCPLINT->battleInt->console->alterTxt == *name)
  172. {
  173. LOCPLINT->battleInt->console->alterTxt = "";
  174. LOCPLINT->battleInt->console->whoSetAlter = 0;
  175. }
  176. }
  177. else if(GH.statusbar) //for other buttons
  178. {
  179. if (on)
  180. GH.statusbar->print(*name);
  181. else if ( GH.statusbar->getCurrent()==(*name) )
  182. GH.statusbar->clear();
  183. }
  184. }
  185. }
  186. void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key)
  187. {
  188. used = LCLICK | RCLICK | HOVER | KEYBOARD;
  189. callback = Callback;
  190. blocked = actOnDown = false;
  191. type=2;
  192. abs=true;
  193. hoverable = false;
  194. //active=false;
  195. ourObj=NULL;
  196. assignedKeys.insert(key);
  197. state=0;
  198. hoverTexts = Name;
  199. helpBox=HelpBox;
  200. setDef(defName, playerColoredButton);
  201. if (add && add->size())
  202. {
  203. imgs.resize(imgs.size()+add->size());
  204. for (size_t i=0; i<add->size();i++)
  205. {
  206. CDefHandler *temp = CDefHandler::giveDef((*add)[i]);
  207. temp->notFreeImgs = true;
  208. for (size_t j=0;j<temp->ourImages.size();j++)
  209. {
  210. imgs[i+1].push_back(temp->ourImages[j].bitmap);
  211. if(playerColoredButton)
  212. {
  213. graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
  214. }
  215. }
  216. delete temp;
  217. }
  218. //delete add;
  219. }
  220. pos.x += x;
  221. pos.y += y;
  222. pos.w = imgs[curimg][0]->w;
  223. pos.h = imgs[curimg][0]->h -1;
  224. }
  225. void AdventureMapButton::block( ui8 on )
  226. {
  227. blocked = on;
  228. state = 0;
  229. bitmapOffset = on ? 2 : 0;
  230. show(screenBuf);
  231. }
  232. void AdventureMapButton::setDef(const std::string & defName, bool playerColoredButton, bool reset/*=false*/)
  233. {
  234. if (reset)
  235. {
  236. for (size_t i=0;i<imgs[0].size();i++)
  237. SDL_FreeSurface(imgs[0][i]);
  238. imgs[0].clear();
  239. }
  240. CDefHandler * temp = CDefHandler::giveDef(defName);
  241. temp->notFreeImgs = true;
  242. for (size_t i=0;i<temp->ourImages.size();i++)
  243. {
  244. imgs.resize(1);
  245. imgs[0].push_back(temp->ourImages[i].bitmap);
  246. if(playerColoredButton)
  247. {
  248. graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
  249. }
  250. }
  251. delete temp;
  252. }
  253. void AdventureMapButton::setPlayerColor(int player)
  254. {
  255. for(int i =0; i<imgs.size();i++)
  256. for(int j=0;j<imgs[i].size();j++)
  257. graphics->blueToPlayersAdv(imgs[i][j],player);
  258. }
  259. void CHighlightableButton::select(bool on)
  260. {
  261. selected = on;
  262. state = selected ? 3 : 0;
  263. if(selected)
  264. callback();
  265. else
  266. callback2();
  267. if(hoverTexts.size()>1)
  268. {
  269. hover(false);
  270. hover(true);
  271. }
  272. }
  273. void CHighlightableButton::clickLeft(tribool down, bool previousState)
  274. {
  275. if(blocked)
  276. return;
  277. if (down)
  278. {
  279. CGI->soundh->playSound(soundBase::button);
  280. state = 1;
  281. }
  282. else
  283. state = selected ? 3 : 0;
  284. show(screenBuf);
  285. if(previousState && down == false)
  286. {
  287. if(!onlyOn || !selected)
  288. select(!selected);
  289. }
  290. }
  291. CHighlightableButton::CHighlightableButton( const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key)
  292. : onlyOn(false), selected(false), callback2(onDeselect)
  293. {
  294. init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,key);
  295. }
  296. CHighlightableButton::CHighlightableButton( const std::pair<std::string, std::string> help, const CFunctionList<void()> &onSelect, int x, int y, const std::string &defName, int myid, int key/*=0*/, std::vector<std::string> * add /*= NULL*/, bool playerColoredButton /*= false */ )
  297. : onlyOn(false), selected(false) // TODO: callback2(???)
  298. {
  299. ID = myid;
  300. std::map<int,std::string> pom;
  301. pom[0] = help.first;
  302. init(onSelect, pom, help.second, playerColoredButton, defName, add, x, y, key);
  303. }
  304. CHighlightableButton::CHighlightableButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &onSelect, int x, int y, const std::string &defName, int myid, int key/*=0*/, std::vector<std::string> * add /*= NULL*/, bool playerColoredButton /*= false */ )
  305. : onlyOn(false), selected(false) // TODO: callback2(???)
  306. {
  307. ID = myid;
  308. std::map<int,std::string> pom;
  309. pom[0] = Name;
  310. init(onSelect, pom,HelpBox, playerColoredButton, defName, add, x, y, key);
  311. }
  312. void CHighlightableButtonsGroup::addButton(CHighlightableButton* bt)
  313. {
  314. bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID);
  315. bt->onlyOn = true;
  316. buttons.push_back(bt);
  317. }
  318. void CHighlightableButtonsGroup::addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect, int key)
  319. {
  320. CHighlightableButton *bt = new CHighlightableButton(OnSelect, 0, tooltip, HelpBox, false, defName, 0, x, y, key);
  321. if(musicLike)
  322. {
  323. bt->bitmapOffset = buttons.size() - 3;
  324. }
  325. bt->ID = uid;
  326. bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID);
  327. bt->onlyOn = true;
  328. buttons.push_back(bt);
  329. }
  330. CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange, bool musicLikeButtons)
  331. : musicLike(musicLikeButtons), onChange(OnChange)
  332. {}
  333. CHighlightableButtonsGroup::~CHighlightableButtonsGroup()
  334. {
  335. for(size_t i=0;i<buttons.size();i++)
  336. {
  337. delete buttons[i];
  338. }
  339. }
  340. void CHighlightableButtonsGroup::activate()
  341. {
  342. for(size_t i=0;i<buttons.size();i++)
  343. {
  344. buttons[i]->activate();
  345. }
  346. }
  347. void CHighlightableButtonsGroup::deactivate()
  348. {
  349. for(size_t i=0;i<buttons.size();i++)
  350. {
  351. buttons[i]->deactivate();
  352. }
  353. }
  354. void CHighlightableButtonsGroup::select(int id, bool mode)
  355. {
  356. CHighlightableButton *bt = NULL;
  357. if(mode)
  358. {
  359. for(size_t i=0;i<buttons.size() && !bt; ++i)
  360. if (buttons[i]->ID == id)
  361. bt = buttons[i];
  362. }
  363. else
  364. {
  365. bt = buttons[id];
  366. }
  367. bt->select(true);
  368. selectionChanged(bt->ID);
  369. }
  370. void CHighlightableButtonsGroup::selectionChanged(int to)
  371. {
  372. for(size_t i=0;i<buttons.size(); ++i)
  373. if(buttons[i]->ID!=to && buttons[i]->selected)
  374. buttons[i]->select(false);
  375. onChange(to);
  376. }
  377. void CHighlightableButtonsGroup::show(SDL_Surface * to )
  378. {
  379. for(size_t i=0;i<buttons.size(); ++i)
  380. {
  381. if(!musicLike || (musicLike && buttons[i]->selected)) //if musicLike, print only selected button
  382. buttons[i]->show(to);
  383. }
  384. }
  385. void CHighlightableButtonsGroup::showAll( SDL_Surface * to )
  386. {
  387. show(to);
  388. }
  389. void CHighlightableButtonsGroup::block( ui8 on )
  390. {
  391. for(size_t i=0;i<buttons.size(); ++i)
  392. {
  393. buttons[i]->block(on);
  394. }
  395. }
  396. void CSlider::sliderClicked()
  397. {
  398. if(!(active & MOVE))
  399. {
  400. activateMouseMove();
  401. used |= MOVE;
  402. }
  403. }
  404. void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  405. {
  406. float v = 0;
  407. if(horizontal)
  408. {
  409. if( std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2+40 || std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2 )
  410. return;
  411. v = sEvent.x - pos.x - 24;
  412. v *= positions;
  413. v /= (pos.w - 48);
  414. }
  415. else
  416. {
  417. if(std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2+40 || std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2 )
  418. return;
  419. v = sEvent.y - pos.y - 24;
  420. v *= positions;
  421. v /= (pos.h - 48);
  422. }
  423. v += 0.5f;
  424. if(v!=value)
  425. {
  426. moveTo(v);
  427. redrawSlider();
  428. }
  429. }
  430. void CSlider::redrawSlider()
  431. {
  432. //slider->show(screenBuf);
  433. }
  434. void CSlider::moveLeft()
  435. {
  436. moveTo(value-1);
  437. }
  438. void CSlider::moveRight()
  439. {
  440. moveTo(value+1);
  441. }
  442. void CSlider::moveTo(int to)
  443. {
  444. amax(to, 0);
  445. amin(to, positions);
  446. //same, old position?
  447. if(value == to)
  448. return;
  449. value = to;
  450. if(horizontal)
  451. {
  452. if(positions)
  453. {
  454. float part = (float)to/positions;
  455. part*=(pos.w-48);
  456. slider->pos.x = part + pos.x + 16;
  457. }
  458. else
  459. slider->pos.x = pos.x+16;
  460. }
  461. else
  462. {
  463. if(positions)
  464. {
  465. float part = (float)to/positions;
  466. part*=(pos.h-48);
  467. slider->pos.y = part + pos.y + 16;
  468. }
  469. else
  470. slider->pos.y = pos.y+16;
  471. }
  472. if(moved)
  473. moved(to);
  474. }
  475. void CSlider::clickLeft(tribool down, bool previousState)
  476. {
  477. if(down && !slider->blocked)
  478. {
  479. float pw = 0;
  480. float rw = 0;
  481. if(horizontal)
  482. {
  483. pw = GH.current->motion.x-pos.x-25;
  484. rw = pw / ((float)(pos.w-48));
  485. }
  486. else
  487. {
  488. pw = GH.current->motion.y-pos.y-24;
  489. rw = pw / ((float)(pos.h-48));
  490. }
  491. if(pw < -8 || pw > (horizontal ? pos.w : pos.h) - 40)
  492. return;
  493. // if (rw>1) return;
  494. // if (rw<0) return;
  495. slider->clickLeft(true, slider->pressedL);
  496. moveTo(rw * positions + 0.5f);
  497. return;
  498. }
  499. if(active & MOVE)
  500. {
  501. deactivateMouseMove();
  502. used &= ~MOVE;
  503. }
  504. }
  505. CSlider::~CSlider()
  506. {
  507. delete imgs;
  508. }
  509. CSlider::CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount, int Value, bool Horizontal, int style)
  510. :capacity(Capacity),amount(Amount),horizontal(Horizontal), moved(Moved)
  511. {
  512. OBJ_CONSTRUCTION_CAPTURING_ALL;
  513. setAmount(amount);
  514. used = LCLICK;
  515. strongInterest = true;
  516. left = new AdventureMapButton;
  517. right = new AdventureMapButton;
  518. slider = new AdventureMapButton;
  519. pos.x += x;
  520. pos.y += y;
  521. if(horizontal)
  522. {
  523. left->pos.y = slider->pos.y = right->pos.y = pos.y;
  524. left->pos.x = pos.x;
  525. right->pos.x = pos.x + totalw - 16;
  526. }
  527. else
  528. {
  529. left->pos.x = slider->pos.x = right->pos.x = pos.x;
  530. left->pos.y = pos.y;
  531. right->pos.y = pos.y + totalw - 16;
  532. }
  533. left->callback = boost::bind(&CSlider::moveLeft,this);
  534. right->callback = boost::bind(&CSlider::moveRight,this);
  535. slider->callback = boost::bind(&CSlider::sliderClicked,this);
  536. left->pos.w = left->pos.h = right->pos.w = right->pos.h = slider->pos.w = slider->pos.h = 16;
  537. if(horizontal)
  538. {
  539. pos.h = 16;
  540. pos.w = totalw;
  541. }
  542. else
  543. {
  544. pos.w = 16;
  545. pos.h = totalw;
  546. }
  547. if(style == 0)
  548. {
  549. if (horizontal)
  550. imgs = CDefHandler::giveDefEss("IGPCRDIV.DEF");
  551. else
  552. imgs = CDefHandler::giveDefEss("OVBUTN2.DEF");
  553. left->imgs.resize(1); right->imgs.resize(1); slider->imgs.resize(1);
  554. left->imgs[0].push_back(imgs->ourImages[0].bitmap); left->imgs[0].push_back(imgs->ourImages[1].bitmap);
  555. right->imgs[0].push_back(imgs->ourImages[2].bitmap); right->imgs[0].push_back(imgs->ourImages[3].bitmap);
  556. slider->imgs[0].push_back(imgs->ourImages[4].bitmap);
  557. left->notFreeButton = right->notFreeButton = slider->notFreeButton = true;
  558. }
  559. else
  560. {
  561. imgs = NULL;
  562. left->setDef(horizontal ? "SCNRBLF.DEF" : "SCNRBUP.DEF", false);
  563. right->setDef(horizontal ? "SCNRBRT.DEF" : "SCNRBDN.DEF", false);
  564. slider->setDef("SCNRBSL.DEF", false);
  565. }
  566. slider->actOnDown = true;
  567. value = -1;
  568. moveTo(Value);
  569. }
  570. void CSlider::block( bool on )
  571. {
  572. left->block(on);
  573. right->block(on);
  574. slider->block(on);
  575. }
  576. void CSlider::setAmount( int to )
  577. {
  578. amount = to;
  579. positions = to - capacity;
  580. amax(positions, 0);
  581. }
  582. void CSlider::showAll(SDL_Surface * to)
  583. {
  584. CSDL_Ext::fillRect(to, &pos, 0);
  585. CIntObject::showAll(to);
  586. }
  587. void CSlider::wheelScrolled(bool down, bool in)
  588. {
  589. moveTo(value + 3 * (down ? +1 : -1));
  590. }
  591. void CSlider::keyPressed(const SDL_KeyboardEvent & key)
  592. {
  593. if(key.state != SDL_PRESSED) return;
  594. int moveDest = 0;
  595. switch(key.keysym.sym)
  596. {
  597. case SDLK_UP:
  598. moveDest = value - 1;
  599. break;
  600. case SDLK_DOWN:
  601. moveDest = value + 1;
  602. break;
  603. case SDLK_PAGEUP:
  604. moveDest = value - capacity + 1;
  605. break;
  606. case SDLK_PAGEDOWN:
  607. moveDest = value + capacity - 1;
  608. break;
  609. case SDLK_HOME:
  610. moveDest = 0;
  611. break;
  612. case SDLK_END:
  613. moveDest = amount - capacity;
  614. break;
  615. default:
  616. return;
  617. }
  618. moveTo(moveDest);
  619. }