2
0

Buttons.cpp 16 KB

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