Buttons.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /*
  2. * Buttons.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "Buttons.h"
  12. #include "Images.h"
  13. #include "TextControls.h"
  14. #include "../CMusicHandler.h"
  15. #include "../CGameInfo.h"
  16. #include "../CPlayerInterface.h"
  17. #include "../battle/CBattleInterface.h"
  18. #include "../battle/CBattleInterfaceClasses.h"
  19. #include "../gui/CAnimation.h"
  20. #include "../gui/CGuiHandler.h"
  21. #include "../windows/InfoWindows.h"
  22. #include "../../lib/CConfigHandler.h"
  23. void CButton::update()
  24. {
  25. if (overlay)
  26. {
  27. if (state == PRESSED)
  28. overlay->moveTo(overlay->pos.centerIn(pos).topLeft() + Point(1,1));
  29. else
  30. overlay->moveTo(overlay->pos.centerIn(pos).topLeft());
  31. }
  32. int newPos = stateToIndex[int(state)];
  33. if(animateLonelyFrame)
  34. {
  35. if(state == PRESSED)
  36. image->moveBy(Point(1,1));
  37. else
  38. image->moveBy(Point(-1,-1));
  39. }
  40. if (newPos < 0)
  41. newPos = 0;
  42. if (state == HIGHLIGHTED && image->size() < 4)
  43. newPos = image->size()-1;
  44. image->setFrame(newPos);
  45. if (active)
  46. redraw();
  47. }
  48. void CButton::addCallback(std::function<void()> callback)
  49. {
  50. this->callback += callback;
  51. }
  52. void CButton::addTextOverlay( const std::string &Text, EFonts font, SDL_Color color)
  53. {
  54. OBJ_CONSTRUCTION_CAPTURING_ALL;
  55. addOverlay(new CLabel(pos.w/2, pos.h/2, font, CENTER, color, Text));
  56. update();
  57. }
  58. void CButton::addOverlay(CIntObject *newOverlay)
  59. {
  60. delete overlay;
  61. overlay = newOverlay;
  62. addChild(newOverlay);
  63. overlay->moveTo(overlay->pos.centerIn(pos).topLeft());
  64. update();
  65. }
  66. void CButton::addImage(std::string filename)
  67. {
  68. imageNames.push_back(filename);
  69. }
  70. void CButton::addHoverText(ButtonState state, std::string text)
  71. {
  72. hoverTexts[state] = text;
  73. }
  74. void CButton::setImageOrder(int state1, int state2, int state3, int state4)
  75. {
  76. stateToIndex[0] = state1;
  77. stateToIndex[1] = state2;
  78. stateToIndex[2] = state3;
  79. stateToIndex[3] = state4;
  80. update();
  81. }
  82. void CButton::setAnimateLonelyFrame(bool agreement)
  83. {
  84. animateLonelyFrame = agreement;
  85. }
  86. void CButton::setState(ButtonState newState)
  87. {
  88. if (state == newState)
  89. return;
  90. state = newState;
  91. update();
  92. }
  93. CButton::ButtonState CButton::getState()
  94. {
  95. return state;
  96. }
  97. bool CButton::isBlocked()
  98. {
  99. return state == BLOCKED;
  100. }
  101. bool CButton::isHighlighted()
  102. {
  103. return state == HIGHLIGHTED;
  104. }
  105. void CButton::block(bool on)
  106. {
  107. if(on || state == BLOCKED) //dont change button state if unblock requested, but it's not blocked
  108. setState(on ? BLOCKED : NORMAL);
  109. }
  110. void CButton::onButtonClicked()
  111. {
  112. // debug logging to figure out pressed button (and as result - player actions) in case of crash
  113. logAnim->trace("Button clicked at %dx%d", pos.x, pos.y);
  114. CIntObject * parent = this->parent;
  115. std::string prefix = "Parent is";
  116. while (parent)
  117. {
  118. logAnim->trace("%s%s at %dx%d", prefix, typeid(*parent).name(), parent->pos.x, parent->pos.y);
  119. parent = parent->parent;
  120. prefix = '\t' + prefix;
  121. }
  122. callback();
  123. }
  124. void CButton::clickLeft(tribool down, bool previousState)
  125. {
  126. if(isBlocked())
  127. return;
  128. if (down)
  129. {
  130. if (!soundDisabled)
  131. CCS->soundh->playSound(soundBase::button);
  132. setState(PRESSED);
  133. }
  134. else if(hoverable && hovered)
  135. setState(HIGHLIGHTED);
  136. else
  137. setState(NORMAL);
  138. if (actOnDown && down)
  139. {
  140. onButtonClicked();
  141. }
  142. else if (!actOnDown && previousState && (down==false))
  143. {
  144. onButtonClicked();
  145. }
  146. }
  147. void CButton::clickRight(tribool down, bool previousState)
  148. {
  149. if(down && helpBox.size()) //there is no point to show window with nothing inside...
  150. CRClickPopup::createAndPush(helpBox);
  151. }
  152. void CButton::hover (bool on)
  153. {
  154. if(hoverable && !isBlocked())
  155. {
  156. if(on)
  157. setState(HIGHLIGHTED);
  158. else
  159. setState(NORMAL);
  160. }
  161. /*if(pressedL && on) // WTF is this? When this is used?
  162. setState(PRESSED);*/
  163. std::string name = hoverTexts[getState()].empty()
  164. ? hoverTexts[0]
  165. : hoverTexts[getState()];
  166. if(!name.empty() && !isBlocked()) //if there is no name, there is nothing to display also
  167. {
  168. if (LOCPLINT && LOCPLINT->battleInt) //for battle buttons
  169. {
  170. if(on && LOCPLINT->battleInt->console->alterTxt == "")
  171. {
  172. LOCPLINT->battleInt->console->alterTxt = name;
  173. LOCPLINT->battleInt->console->whoSetAlter = 1;
  174. }
  175. else if (LOCPLINT->battleInt->console->alterTxt == name)
  176. {
  177. LOCPLINT->battleInt->console->alterTxt = "";
  178. LOCPLINT->battleInt->console->whoSetAlter = 0;
  179. }
  180. }
  181. else if(GH.statusbar) //for other buttons
  182. {
  183. if (on)
  184. GH.statusbar->setText(name);
  185. else if ( GH.statusbar->getText()==(name) )
  186. GH.statusbar->clear();
  187. }
  188. }
  189. }
  190. CButton::CButton(Point position, const std::string &defName, const std::pair<std::string, std::string> &help, CFunctionList<void()> Callback, int key, bool playerColoredButton):
  191. CKeyShortcut(key),
  192. callback(Callback)
  193. {
  194. addUsedEvents(LCLICK | RCLICK | HOVER | KEYBOARD);
  195. stateToIndex[0] = 0;
  196. stateToIndex[1] = 1;
  197. stateToIndex[2] = 2;
  198. stateToIndex[3] = 3;
  199. state=NORMAL;
  200. image = nullptr;
  201. overlay = nullptr;
  202. currentImage = -1;
  203. hoverable = actOnDown = soundDisabled = false;
  204. hoverTexts[0] = help.first;
  205. helpBox=help.second;
  206. pos.x += position.x;
  207. pos.y += position.y;
  208. if (!defName.empty())
  209. {
  210. imageNames.push_back(defName);
  211. setIndex(0, playerColoredButton);
  212. }
  213. }
  214. void CButton::setIndex(size_t index, bool playerColoredButton)
  215. {
  216. if (index == currentImage || index>=imageNames.size())
  217. return;
  218. currentImage = index;
  219. auto anim = std::make_shared<CAnimation>(imageNames[index]);
  220. setImage(anim, playerColoredButton);
  221. }
  222. void CButton::setImage(std::shared_ptr<CAnimation> anim, bool playerColoredButton, int animFlags)
  223. {
  224. OBJ_CONSTRUCTION_CAPTURING_ALL;
  225. image = new CAnimImage(anim, getState(), 0, 0, 0, animFlags);
  226. if (playerColoredButton)
  227. image->playerColored(LOCPLINT->playerID);
  228. pos = image->pos;
  229. }
  230. void CButton::setPlayerColor(PlayerColor player)
  231. {
  232. if (image)
  233. image->playerColored(player);
  234. }
  235. void CButton::showAll(SDL_Surface * to)
  236. {
  237. CIntObject::showAll(to);
  238. if (borderColor && borderColor->a == 0)
  239. CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor->r, borderColor->g, borderColor->b));
  240. }
  241. std::pair<std::string, std::string> CButton::tooltip()
  242. {
  243. return std::pair<std::string, std::string>();
  244. }
  245. std::pair<std::string, std::string> CButton::tooltip(const JsonNode & localizedTexts)
  246. {
  247. return std::make_pair(localizedTexts["label"].String(), localizedTexts["help"].String());
  248. }
  249. std::pair<std::string, std::string> CButton::tooltip(const std::string & hover, const std::string & help)
  250. {
  251. return std::make_pair(hover, help);
  252. }
  253. CToggleBase::CToggleBase(CFunctionList<void (bool)> callback):
  254. callback(callback),
  255. selected(false),
  256. allowDeselection(true)
  257. {
  258. }
  259. CToggleBase::~CToggleBase()
  260. {
  261. }
  262. void CToggleBase::doSelect(bool on)
  263. {
  264. // for overrides
  265. }
  266. void CToggleBase::setSelected(bool on)
  267. {
  268. bool changed = (on != selected);
  269. selected = on;
  270. doSelect(on);
  271. if (changed)
  272. callback(on);
  273. }
  274. bool CToggleBase::canActivate()
  275. {
  276. if (selected && !allowDeselection)
  277. return false;
  278. return true;
  279. }
  280. void CToggleBase::addCallback(std::function<void(bool)> function)
  281. {
  282. callback += function;
  283. }
  284. CToggleButton::CToggleButton(Point position, const std::string &defName, const std::pair<std::string, std::string> &help,
  285. CFunctionList<void(bool)> callback, int key, bool playerColoredButton):
  286. CButton(position, defName, help, 0, key, playerColoredButton),
  287. CToggleBase(callback)
  288. {
  289. allowDeselection = true;
  290. }
  291. void CToggleButton::doSelect(bool on)
  292. {
  293. if (on)
  294. {
  295. setState(HIGHLIGHTED);
  296. }
  297. else
  298. {
  299. setState(NORMAL);
  300. }
  301. }
  302. void CToggleButton::clickLeft(tribool down, bool previousState)
  303. {
  304. // force refresh
  305. hover(false);
  306. hover(true);
  307. if(isBlocked())
  308. return;
  309. if (down && canActivate())
  310. {
  311. CCS->soundh->playSound(soundBase::button);
  312. setState(PRESSED);
  313. }
  314. if(previousState)//mouse up
  315. {
  316. if(down == false && getState() == PRESSED && canActivate())
  317. {
  318. onButtonClicked();
  319. setSelected(!selected);
  320. }
  321. else
  322. doSelect(selected); // restore
  323. }
  324. }
  325. void CToggleGroup::addCallback(std::function<void(int)> callback)
  326. {
  327. onChange += callback;
  328. }
  329. void CToggleGroup::addToggle(int identifier, CToggleBase* bt)
  330. {
  331. if (auto intObj = dynamic_cast<CIntObject*>(bt)) // hack-ish workagound to avoid diamond problem with inheritance
  332. {
  333. if (intObj->parent)
  334. intObj->parent->removeChild(intObj);
  335. addChild(intObj);
  336. }
  337. bt->addCallback([=] (bool on) { if (on) selectionChanged(identifier);});
  338. bt->allowDeselection = false;
  339. assert(buttons[identifier] == nullptr);
  340. buttons[identifier] = bt;
  341. }
  342. CToggleGroup::CToggleGroup(const CFunctionList<void(int)> &OnChange)
  343. : onChange(OnChange), selectedID(-2)
  344. {}
  345. void CToggleGroup::setSelected(int id)
  346. {
  347. selectionChanged(id);
  348. }
  349. void CToggleGroup::selectionChanged(int to)
  350. {
  351. if (to == selectedID)
  352. return;
  353. int oldSelection = selectedID;
  354. selectedID = to;
  355. if (buttons.count(oldSelection))
  356. buttons[oldSelection]->setSelected(false);
  357. if (buttons.count(to))
  358. buttons[to]->setSelected(true);
  359. onChange(to);
  360. if (parent)
  361. parent->redraw();
  362. }
  363. CVolumeSlider::CVolumeSlider(const Point &position, const std::string &defName, const int value,
  364. const std::pair<std::string, std::string> * const help) :
  365. value(value),
  366. helpHandlers(help)
  367. {
  368. OBJ_CONSTRUCTION_CAPTURING_ALL;
  369. animImage = new CAnimImage(std::make_shared<CAnimation>(defName), 0, 0, position.x, position.y),
  370. assert(!defName.empty());
  371. addUsedEvents(LCLICK | RCLICK | WHEEL);
  372. pos.x += position.x;
  373. pos.y += position.y;
  374. pos.w = (animImage->pos.w + 1) * animImage->size();
  375. pos.h = animImage->pos.h;
  376. type |= REDRAW_PARENT;
  377. setVolume(value);
  378. }
  379. void CVolumeSlider::setVolume(int value_)
  380. {
  381. value = value_;
  382. moveTo(value * static_cast<double>(animImage->size()) / 100.0);
  383. }
  384. void CVolumeSlider::moveTo(int id)
  385. {
  386. vstd::abetween(id, 0, animImage->size() - 1);
  387. animImage->setFrame(id);
  388. animImage->moveTo(Point(pos.x + (animImage->pos.w + 1) * id, pos.y));
  389. if (active)
  390. redraw();
  391. }
  392. void CVolumeSlider::addCallback(std::function<void(int)> callback)
  393. {
  394. onChange += callback;
  395. }
  396. void CVolumeSlider::clickLeft(tribool down, bool previousState)
  397. {
  398. if (down)
  399. {
  400. double px = GH.current->motion.x - pos.x;
  401. double rx = px / static_cast<double>(pos.w);
  402. // setVolume is out of 100
  403. setVolume(rx * 100);
  404. // Volume config is out of 100, set to increments of 5ish roughly based on the half point of the indicator
  405. // 0.0 -> 0, 0.05 -> 5, 0.09 -> 5,...,
  406. // 0.1 -> 10, ..., 0.19 -> 15, 0.2 -> 20, ...,
  407. // 0.28 -> 25, 0.29 -> 30, 0.3 -> 30, ...,
  408. // 0.85 -> 85, 0.86 -> 90, ..., 0.87 -> 90,...,
  409. // 0.95 -> 95, 0.96 -> 100, 0.99 -> 100
  410. int volume = 5 * int(rx * (2 * animImage->size() + 1));
  411. onChange(volume);
  412. }
  413. }
  414. void CVolumeSlider::clickRight(tribool down, bool previousState)
  415. {
  416. if (down)
  417. {
  418. double px = GH.current->motion.x - pos.x;
  419. int index = px / static_cast<double>(pos.w) * animImage->size();
  420. std::string hoverText = helpHandlers[index].first;
  421. std::string helpBox = helpHandlers[index].second;
  422. if(!helpBox.empty())
  423. CRClickPopup::createAndPush(helpBox);
  424. if(GH.statusbar)
  425. GH.statusbar->setText(helpBox);
  426. }
  427. }
  428. void CVolumeSlider::wheelScrolled(bool down, bool in)
  429. {
  430. if (in)
  431. {
  432. int volume = value + 3 * (down ? 1 : -1);
  433. vstd::abetween(volume, 0, 100);
  434. setVolume(volume);
  435. onChange(volume);
  436. }
  437. }
  438. void CSlider::sliderClicked()
  439. {
  440. if(!(active & MOVE))
  441. addUsedEvents(MOVE);
  442. }
  443. void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  444. {
  445. double v = 0;
  446. if(horizontal)
  447. {
  448. 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 )
  449. return;
  450. v = sEvent.x - pos.x - 24;
  451. v *= positions;
  452. v /= (pos.w - 48);
  453. }
  454. else
  455. {
  456. 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 )
  457. return;
  458. v = sEvent.y - pos.y - 24;
  459. v *= positions;
  460. v /= (pos.h - 48);
  461. }
  462. v += 0.5;
  463. if(v!=value)
  464. {
  465. moveTo(v);
  466. }
  467. }
  468. void CSlider::setScrollStep(int to)
  469. {
  470. scrollStep = to;
  471. }
  472. int CSlider::getAmount()
  473. {
  474. return amount;
  475. }
  476. int CSlider::getValue()
  477. {
  478. return value;
  479. }
  480. void CSlider::moveLeft()
  481. {
  482. moveTo(value-1);
  483. }
  484. void CSlider::moveRight()
  485. {
  486. moveTo(value+1);
  487. }
  488. void CSlider::moveBy(int amount)
  489. {
  490. moveTo(value + amount);
  491. }
  492. void CSlider::updateSliderPos()
  493. {
  494. if(horizontal)
  495. {
  496. if(positions)
  497. {
  498. double part = static_cast<double>(value) / positions;
  499. part*=(pos.w-48);
  500. int newPos = part + pos.x + 16 - slider->pos.x;
  501. slider->moveBy(Point(newPos, 0));
  502. }
  503. else
  504. slider->moveTo(Point(pos.x+16, pos.y));
  505. }
  506. else
  507. {
  508. if(positions)
  509. {
  510. double part = static_cast<double>(value) / positions;
  511. part*=(pos.h-48);
  512. int newPos = part + pos.y + 16 - slider->pos.y;
  513. slider->moveBy(Point(0, newPos));
  514. }
  515. else
  516. slider->moveTo(Point(pos.x, pos.y+16));
  517. }
  518. }
  519. void CSlider::moveTo(int to)
  520. {
  521. vstd::amax(to, 0);
  522. vstd::amin(to, positions);
  523. //same, old position?
  524. if(value == to)
  525. return;
  526. value = to;
  527. updateSliderPos();
  528. moved(to);
  529. }
  530. void CSlider::clickLeft(tribool down, bool previousState)
  531. {
  532. if(down && !slider->isBlocked())
  533. {
  534. double pw = 0;
  535. double rw = 0;
  536. if(horizontal)
  537. {
  538. pw = GH.current->motion.x-pos.x-25;
  539. rw = pw / static_cast<double>(pos.w - 48);
  540. }
  541. else
  542. {
  543. pw = GH.current->motion.y-pos.y-24;
  544. rw = pw / (pos.h-48);
  545. }
  546. if(pw < -8 || pw > (horizontal ? pos.w : pos.h) - 40)
  547. return;
  548. // if (rw>1) return;
  549. // if (rw<0) return;
  550. slider->clickLeft(true, slider->mouseState(EIntObjMouseBtnType::LEFT));
  551. moveTo(rw * positions + 0.5);
  552. return;
  553. }
  554. if(active & MOVE)
  555. removeUsedEvents(MOVE);
  556. }
  557. CSlider::~CSlider()
  558. {
  559. }
  560. CSlider::CSlider(Point position, int totalw, std::function<void(int)> Moved, int Capacity, int Amount, int Value, bool Horizontal, CSlider::EStyle style):
  561. capacity(Capacity),
  562. horizontal(Horizontal),
  563. amount(Amount),
  564. value(Value),
  565. scrollStep(1),
  566. moved(Moved)
  567. {
  568. OBJ_CONSTRUCTION_CAPTURING_ALL;
  569. setAmount(amount);
  570. vstd::amax(value, 0);
  571. vstd::amin(value, positions);
  572. addUsedEvents(LCLICK | KEYBOARD | WHEEL);
  573. strongInterest = true;
  574. pos.x += position.x;
  575. pos.y += position.y;
  576. if(style == BROWN)
  577. {
  578. std::string name = horizontal?"IGPCRDIV.DEF":"OVBUTN2.DEF";
  579. //NOTE: this images do not have "blocked" frames. They should be implemented somehow (e.g. palette transform or something...)
  580. left = new CButton(Point(), name, CButton::tooltip());
  581. right = new CButton(Point(), name, CButton::tooltip());
  582. slider = new CButton(Point(), name, CButton::tooltip());
  583. left->setImageOrder(0, 1, 1, 1);
  584. right->setImageOrder(2, 3, 3, 3);
  585. slider->setImageOrder(4, 4, 4, 4);
  586. }
  587. else
  588. {
  589. left = new CButton(Point(), horizontal ? "SCNRBLF.DEF" : "SCNRBUP.DEF", CButton::tooltip());
  590. right = new CButton(Point(), horizontal ? "SCNRBRT.DEF" : "SCNRBDN.DEF", CButton::tooltip());
  591. slider = new CButton(Point(), "SCNRBSL.DEF", CButton::tooltip());
  592. }
  593. slider->actOnDown = true;
  594. slider->soundDisabled = true;
  595. left->soundDisabled = true;
  596. right->soundDisabled = true;
  597. if (horizontal)
  598. right->moveBy(Point(totalw - right->pos.w, 0));
  599. else
  600. right->moveBy(Point(0, totalw - right->pos.h));
  601. left->addCallback(std::bind(&CSlider::moveLeft,this));
  602. right->addCallback(std::bind(&CSlider::moveRight,this));
  603. slider->addCallback(std::bind(&CSlider::sliderClicked,this));
  604. if(horizontal)
  605. {
  606. pos.h = slider->pos.h;
  607. pos.w = totalw;
  608. }
  609. else
  610. {
  611. pos.w = slider->pos.w;
  612. pos.h = totalw;
  613. }
  614. updateSliderPos();
  615. }
  616. void CSlider::block( bool on )
  617. {
  618. left->block(on);
  619. right->block(on);
  620. slider->block(on);
  621. }
  622. void CSlider::setAmount( int to )
  623. {
  624. amount = to;
  625. positions = to - capacity;
  626. vstd::amax(positions, 0);
  627. }
  628. void CSlider::showAll(SDL_Surface * to)
  629. {
  630. CSDL_Ext::fillRectBlack(to, &pos);
  631. CIntObject::showAll(to);
  632. }
  633. void CSlider::wheelScrolled(bool down, bool in)
  634. {
  635. moveTo(value + 3 * (down ? +scrollStep : -scrollStep));
  636. }
  637. void CSlider::keyPressed(const SDL_KeyboardEvent & key)
  638. {
  639. if(key.state != SDL_PRESSED) return;
  640. int moveDest = value;
  641. switch(key.keysym.sym)
  642. {
  643. case SDLK_UP:
  644. if (!horizontal)
  645. moveDest = value - scrollStep;
  646. break;
  647. case SDLK_LEFT:
  648. if (horizontal)
  649. moveDest = value - scrollStep;
  650. break;
  651. case SDLK_DOWN:
  652. if (!horizontal)
  653. moveDest = value + scrollStep;
  654. break;
  655. case SDLK_RIGHT:
  656. if (horizontal)
  657. moveDest = value + scrollStep;
  658. break;
  659. case SDLK_PAGEUP:
  660. moveDest = value - capacity + scrollStep;
  661. break;
  662. case SDLK_PAGEDOWN:
  663. moveDest = value + capacity - scrollStep;
  664. break;
  665. case SDLK_HOME:
  666. moveDest = 0;
  667. break;
  668. case SDLK_END:
  669. moveDest = amount - capacity;
  670. break;
  671. default:
  672. return;
  673. }
  674. moveTo(moveDest);
  675. }
  676. void CSlider::moveToMin()
  677. {
  678. moveTo(0);
  679. }
  680. void CSlider::moveToMax()
  681. {
  682. moveTo(amount);
  683. }