Buttons.cpp 16 KB

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