2
0

AdventureMapButton.cpp 17 KB

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