Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

802 lines
22 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <assert.h>
  8. #include <vgui/IScheme.h>
  9. #include <vgui/ISystem.h>
  10. #include <vgui/IInput.h>
  11. #include <vgui/IImage.h>
  12. #include <KeyValues.h>
  13. #include <vgui_controls/ScrollBar.h>
  14. #include <vgui_controls/ScrollBarSlider.h>
  15. #include <vgui_controls/Button.h>
  16. #include <vgui_controls/Controls.h>
  17. #include <vgui_controls/ImagePanel.h>
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include <tier0/memdbgon.h>
  20. using namespace vgui;
  21. namespace
  22. {
  23. enum
  24. { // scroll bar will scroll a little, then continuous scroll like in windows
  25. SCROLL_BAR_DELAY = 400, // default delay for all scroll bars
  26. SCROLL_BAR_SPEED = 50, // this is how fast the bar scrolls when you hold down the arrow button
  27. SCROLLBAR_DEFAULT_WIDTH = 17,
  28. };
  29. //-----------------------------------------------------------------------------
  30. // Purpose: Scroll bar button-the arrow button that moves the slider up and down.
  31. //-----------------------------------------------------------------------------
  32. class ScrollBarButton : public Button
  33. {
  34. public:
  35. ScrollBarButton(Panel *parent, const char *panelName, const char *text) : Button(parent, panelName, text)
  36. {
  37. SetButtonActivationType(ACTIVATE_ONPRESSED);
  38. SetContentAlignment(Label::a_center);
  39. }
  40. void OnMouseFocusTicked()
  41. {
  42. // pass straight up to parent
  43. CallParentFunction(new KeyValues("MouseFocusTicked"));
  44. }
  45. virtual void ApplySchemeSettings(IScheme *pScheme)
  46. {
  47. Button::ApplySchemeSettings(pScheme);
  48. SetFont(pScheme->GetFont("Marlett", IsProportional() ));
  49. SetDefaultBorder(pScheme->GetBorder("ScrollBarButtonBorder"));
  50. SetDepressedBorder(pScheme->GetBorder("ScrollBarButtonDepressedBorder"));
  51. SetDefaultColor(GetSchemeColor("ScrollBarButton.FgColor", pScheme), GetSchemeColor("ScrollBarButton.BgColor", pScheme));
  52. SetArmedColor(GetSchemeColor("ScrollBarButton.ArmedFgColor", pScheme), GetSchemeColor("ScrollBarButton.ArmedBgColor", pScheme));
  53. SetDepressedColor(GetSchemeColor("ScrollBarButton.DepressedFgColor", pScheme), GetSchemeColor("ScrollBarButton.DepressedBgColor", pScheme));
  54. }
  55. // Don't request focus.
  56. // This will keep cursor focus in main window in text entry windows.
  57. virtual void OnMousePressed(MouseCode code)
  58. {
  59. if (!IsEnabled())
  60. return;
  61. if (!IsMouseClickEnabled(code))
  62. return;
  63. if (IsUseCaptureMouseEnabled())
  64. {
  65. {
  66. SetSelected(true);
  67. Repaint();
  68. }
  69. // lock mouse input to going to this button
  70. input()->SetMouseCapture(GetVPanel());
  71. }
  72. }
  73. virtual void OnMouseReleased(MouseCode code)
  74. {
  75. if (!IsEnabled())
  76. return;
  77. if (!IsMouseClickEnabled(code))
  78. return;
  79. if (IsUseCaptureMouseEnabled())
  80. {
  81. {
  82. SetSelected(false);
  83. Repaint();
  84. }
  85. // lock mouse input to going to this button
  86. input()->SetMouseCapture(NULL);
  87. }
  88. if( input()->GetMouseOver() == GetVPanel() )
  89. {
  90. SetArmed( true );
  91. }
  92. }
  93. };
  94. }
  95. vgui::Panel *ScrollBar_Vertical_Factory()
  96. {
  97. return new ScrollBar(NULL, NULL, true );
  98. }
  99. vgui::Panel *ScrollBar_Horizontal_Factory()
  100. {
  101. return new ScrollBar(NULL, NULL, false );
  102. }
  103. DECLARE_BUILD_FACTORY_CUSTOM_ALIAS( ScrollBar, ScrollBar_Vertical, ScrollBar_Vertical_Factory );
  104. DECLARE_BUILD_FACTORY_CUSTOM_ALIAS( ScrollBar, ScrollBar_Horizontal, ScrollBar_Horizontal_Factory );
  105. // Default is a horizontal one
  106. DECLARE_BUILD_FACTORY_CUSTOM( ScrollBar, ScrollBar_Horizontal_Factory );
  107. //-----------------------------------------------------------------------------
  108. // Purpose: Constructor
  109. //-----------------------------------------------------------------------------
  110. ScrollBar::ScrollBar(Panel *parent, const char *panelName, bool vertical) : Panel(parent, panelName)
  111. {
  112. _slider=null;
  113. _button[0]=null;
  114. _button[1]=null;
  115. _scrollDelay = SCROLL_BAR_DELAY;
  116. _respond = true;
  117. m_pUpArrow = NULL;
  118. m_pLine = NULL;
  119. m_pDownArrow = NULL;
  120. m_pBox = NULL;
  121. m_bNoButtons = false;
  122. m_pOverriddenButtons[0] = NULL;
  123. m_pOverriddenButtons[1] = NULL;
  124. if (vertical)
  125. {
  126. // FIXME: proportional changes needed???
  127. SetSlider(new ScrollBarSlider(NULL, "Slider", true));
  128. SetButton(new ScrollBarButton(NULL, "UpButton", "t"), 0);
  129. SetButton(new ScrollBarButton(NULL, "DownButton", "u"), 1);
  130. _button[0]->SetTextInset(0, 1);
  131. _button[1]->SetTextInset(0, -1);
  132. SetSize(SCROLLBAR_DEFAULT_WIDTH, 64);
  133. }
  134. else
  135. {
  136. SetSlider(new ScrollBarSlider(NULL, NULL, false));
  137. SetButton(new ScrollBarButton(NULL, NULL, "w"), 0);
  138. SetButton(new ScrollBarButton(NULL, NULL, "4"), 1);
  139. _button[0]->SetTextInset(0, 0);
  140. _button[1]->SetTextInset(0, 0);
  141. SetSize(64, SCROLLBAR_DEFAULT_WIDTH);
  142. }
  143. Panel::SetPaintBorderEnabled(true);
  144. Panel::SetPaintBackgroundEnabled(false);
  145. Panel::SetPaintEnabled(true);
  146. SetButtonPressedScrollValue(20);
  147. SetBlockDragChaining( true );
  148. Validate();
  149. }
  150. //-----------------------------------------------------------------------------
  151. // Purpose: sets up the width of the scrollbar according to the scheme
  152. //-----------------------------------------------------------------------------
  153. void ScrollBar::ApplySchemeSettings(IScheme *pScheme)
  154. {
  155. BaseClass::ApplySchemeSettings(pScheme);
  156. const char *resourceString = pScheme->GetResourceString("ScrollBar.Wide");
  157. if (resourceString)
  158. {
  159. int value = atoi(resourceString);
  160. if (IsProportional())
  161. {
  162. value = scheme()->GetProportionalScaledValueEx(GetScheme(), value);
  163. }
  164. if (_slider && _slider->IsVertical())
  165. {
  166. // we're vertical, so reset the width
  167. SetSize( value, GetTall() );
  168. }
  169. else
  170. {
  171. // we're horizontal, so the width means the height
  172. SetSize( GetWide(), value );
  173. }
  174. }
  175. UpdateButtonsForImages();
  176. }
  177. //-----------------------------------------------------------------------------
  178. // Purpose: Set the slider's Paint border enabled.
  179. //-----------------------------------------------------------------------------
  180. void ScrollBar::SetPaintBorderEnabled(bool state)
  181. {
  182. if ( _slider )
  183. {
  184. _slider->SetPaintBorderEnabled( state );
  185. }
  186. }
  187. //-----------------------------------------------------------------------------
  188. // Purpose:
  189. //-----------------------------------------------------------------------------
  190. void ScrollBar::SetPaintBackgroundEnabled(bool state)
  191. {
  192. if ( _slider )
  193. {
  194. _slider->SetPaintBackgroundEnabled( state );
  195. }
  196. }
  197. //-----------------------------------------------------------------------------
  198. // Purpose:
  199. //-----------------------------------------------------------------------------
  200. void ScrollBar::SetPaintEnabled(bool state)
  201. {
  202. if ( _slider )
  203. {
  204. _slider->SetPaintEnabled( state );
  205. }
  206. }
  207. //-----------------------------------------------------------------------------
  208. // Purpose: Layout the scroll bar and buttons on screen
  209. //-----------------------------------------------------------------------------
  210. void ScrollBar::PerformLayout()
  211. {
  212. if (_slider)
  213. {
  214. int wide, tall;
  215. GetPaintSize(wide,tall);
  216. if(_slider->IsVertical())
  217. {
  218. if ( m_bNoButtons )
  219. {
  220. _slider->SetBounds(0, 0, wide, tall + 1);
  221. }
  222. else
  223. {
  224. _slider->SetBounds(0, wide, wide, tall-(wide*2)+1);
  225. _button[0]->SetBounds(0,0, wide, wide );
  226. _button[1]->SetBounds(0,tall-wide ,wide, wide );
  227. }
  228. }
  229. else
  230. {
  231. if ( m_bNoButtons )
  232. {
  233. _slider->SetBounds(tall, 0, wide, tall + 1);
  234. }
  235. else
  236. {
  237. _slider->SetBounds(tall, -1, wide-(tall*2)+1, tall + 1 );
  238. _button[0]->SetBounds(0, 0, tall, tall);
  239. _button[1]->SetBounds(wide-tall, 0, tall, tall);
  240. }
  241. }
  242. // Place the images over the appropriate controls
  243. int x,y;
  244. if ( m_pUpArrow )
  245. {
  246. _button[0]->GetBounds( x,y,wide,tall );
  247. m_pUpArrow->SetBounds( x,y,wide,tall );
  248. }
  249. if ( m_pDownArrow )
  250. {
  251. _button[1]->GetBounds( x,y,wide,tall );
  252. m_pDownArrow->SetBounds( x,y,wide,tall );
  253. }
  254. if ( m_pLine )
  255. {
  256. _slider->GetBounds( x,y,wide,tall );
  257. m_pLine->SetBounds( x,y,wide,tall );
  258. }
  259. if ( m_pBox )
  260. {
  261. m_pBox->SetBounds( 0, wide, wide, wide );
  262. }
  263. _slider->MoveToFront();
  264. // after resizing our child, we should remind it to perform a layout
  265. _slider->InvalidateLayout();
  266. UpdateSliderImages();
  267. }
  268. if ( m_bAutoHideButtons )
  269. {
  270. SetScrollbarButtonsVisible( _slider->IsSliderVisible() );
  271. }
  272. // get tooltips to draw
  273. Panel::PerformLayout();
  274. }
  275. //-----------------------------------------------------------------------------
  276. // Purpose: Set the value of the scroll bar slider.
  277. //-----------------------------------------------------------------------------
  278. void ScrollBar::SetValue(int value)
  279. {
  280. _slider->SetValue(value);
  281. }
  282. //-----------------------------------------------------------------------------
  283. // Purpose: Get the value of the scroll bar slider.
  284. //-----------------------------------------------------------------------------
  285. int ScrollBar::GetValue()
  286. {
  287. return _slider->GetValue();
  288. }
  289. //-----------------------------------------------------------------------------
  290. // Purpose: Set the range of the scroll bar slider.
  291. // This the range of numbers the slider can scroll through.
  292. //-----------------------------------------------------------------------------
  293. void ScrollBar::SetRange(int min,int max)
  294. {
  295. _slider->SetRange(min,max);
  296. }
  297. //-----------------------------------------------------------------------------
  298. // Purpose: Gets the range of the scroll bar slider.
  299. // This the range of numbers the slider can scroll through.
  300. //-----------------------------------------------------------------------------
  301. void ScrollBar::GetRange(int &min, int &max)
  302. {
  303. _slider->GetRange(min, max);
  304. }
  305. //-----------------------------------------------------------------------------
  306. // Purpose: Send a message when the slider is moved.
  307. // Input : value -
  308. //-----------------------------------------------------------------------------
  309. void ScrollBar::SendSliderMoveMessage(int value)
  310. {
  311. PostActionSignal(new KeyValues("ScrollBarSliderMoved", "position", value));
  312. }
  313. //-----------------------------------------------------------------------------
  314. // Purpose: Called when the Slider is dragged by the user
  315. // Input : value -
  316. //-----------------------------------------------------------------------------
  317. void ScrollBar::OnSliderMoved(int value)
  318. {
  319. SendSliderMoveMessage(value);
  320. UpdateSliderImages();
  321. }
  322. //-----------------------------------------------------------------------------
  323. // Purpose: Check if the scrollbar is vertical (true) or horizontal (false)
  324. //-----------------------------------------------------------------------------
  325. bool ScrollBar::IsVertical()
  326. {
  327. return _slider->IsVertical();
  328. }
  329. //-----------------------------------------------------------------------------
  330. // Purpose: Check if the the scrollbar slider has full range.
  331. // Normally if you have a scroll bar and the range goes from a to b and
  332. // the slider is sized to c, the range will go from a to b-c.
  333. // This makes it so the slider goes from a to b fully.
  334. //-----------------------------------------------------------------------------
  335. bool ScrollBar::HasFullRange()
  336. {
  337. return _slider->HasFullRange();
  338. }
  339. //-----------------------------------------------------------------------------
  340. // Purpose: Setup the indexed scroll bar button with the input params.
  341. //-----------------------------------------------------------------------------
  342. //LEAK: new and old slider will leak
  343. void ScrollBar::SetButton(Button *button, int index)
  344. {
  345. if(_button[index]!=null)
  346. {
  347. _button[index]->SetParent((Panel *)NULL);
  348. }
  349. _button[index]=button;
  350. _button[index]->SetParent(this);
  351. _button[index]->AddActionSignalTarget(this);
  352. _button[index]->SetCommand(new KeyValues("ScrollButtonPressed", "index", index));
  353. Validate();
  354. }
  355. //-----------------------------------------------------------------------------
  356. // Purpose: Return the indexed scroll bar button
  357. //-----------------------------------------------------------------------------
  358. Button* ScrollBar::GetButton(int index)
  359. {
  360. return _button[index];
  361. }
  362. //-----------------------------------------------------------------------------
  363. // Purpose: Set up the slider.
  364. //-----------------------------------------------------------------------------
  365. //LEAK: new and old slider will leak
  366. void ScrollBar::SetSlider(ScrollBarSlider *slider)
  367. {
  368. if(_slider!=null)
  369. {
  370. _slider->SetParent((Panel *)NULL);
  371. }
  372. _slider=slider;
  373. _slider->AddActionSignalTarget(this);
  374. _slider->SetParent(this);
  375. Validate();
  376. }
  377. //-----------------------------------------------------------------------------
  378. // Purpose: Return a pointer to the slider.
  379. //-----------------------------------------------------------------------------
  380. ScrollBarSlider *ScrollBar::GetSlider()
  381. {
  382. return _slider;
  383. }
  384. Button *ScrollBar::GetDepressedButton( int iIndex )
  385. {
  386. if ( iIndex == 0 )
  387. return ( m_pOverriddenButtons[0] ? m_pOverriddenButtons[0] : _button[0] );
  388. return ( m_pOverriddenButtons[1] ? m_pOverriddenButtons[1] : _button[1] );
  389. }
  390. //-----------------------------------------------------------------------------
  391. // Purpose: Scrolls in response to clicking and holding on up or down arrow
  392. // The idea is to have the slider move one step then delay a bit and then
  393. // the bar starts moving at normal speed. This gives a stepping feeling
  394. // to just clicking an arrow once.
  395. //-----------------------------------------------------------------------------
  396. void ScrollBar::OnMouseFocusTicked()
  397. {
  398. int direction = 0;
  399. // top button is down
  400. if ( GetDepressedButton(0)->IsDepressed() )
  401. {
  402. direction = -1;
  403. }
  404. // bottom top button is down
  405. else if (GetDepressedButton(1)->IsDepressed())
  406. {
  407. direction = 1;
  408. }
  409. // a button is down
  410. if ( direction != 0 )
  411. {
  412. RespondToScrollArrow(direction);
  413. if (_scrollDelay < system()->GetTimeMillis())
  414. {
  415. _scrollDelay = system()->GetTimeMillis() + SCROLL_BAR_SPEED;
  416. _respond = true;
  417. }
  418. else
  419. {
  420. _respond = false;
  421. }
  422. }
  423. // a button is not down.
  424. else
  425. {
  426. // if neither button is down keep delay at max
  427. _scrollDelay = system()->GetTimeMillis() + SCROLL_BAR_DELAY;
  428. _respond = true;
  429. }
  430. }
  431. //-----------------------------------------------------------------------------
  432. // Purpose: move scroll bar in response to the first button
  433. // Input: button and direction to move scroll bar when that button is pressed
  434. // direction can only by +/- 1
  435. // Output: whether button is down or not
  436. //-----------------------------------------------------------------------------
  437. void ScrollBar::RespondToScrollArrow(int const direction)
  438. {
  439. if (_respond)
  440. {
  441. int newValue = _slider->GetValue() + (direction * _buttonPressedScrollValue);
  442. _slider->SetValue(newValue);
  443. SendSliderMoveMessage(newValue);
  444. }
  445. }
  446. //-----------------------------------------------------------------------------
  447. // Purpose: Trigger layout changes when the window size is changed.
  448. //-----------------------------------------------------------------------------
  449. void ScrollBar::OnSizeChanged(int wide, int tall)
  450. {
  451. InvalidateLayout();
  452. _slider->InvalidateLayout();
  453. }
  454. //-----------------------------------------------------------------------------
  455. // Purpose: Set how far the scroll bar slider moves when a scroll bar button is
  456. // pressed.
  457. //-----------------------------------------------------------------------------
  458. void ScrollBar::SetButtonPressedScrollValue(int value)
  459. {
  460. _buttonPressedScrollValue=value;
  461. }
  462. //-----------------------------------------------------------------------------
  463. // Purpose: Set the range of the rangewindow. This is how many
  464. // lines are displayed at one time
  465. // in the window the scroll bar is attached to.
  466. // This also controls the size of the slider, its size is proportional
  467. // to the number of lines displayed / total number of lines.
  468. //-----------------------------------------------------------------------------
  469. void ScrollBar::SetRangeWindow(int rangeWindow)
  470. {
  471. _slider->SetRangeWindow(rangeWindow);
  472. }
  473. //-----------------------------------------------------------------------------
  474. // Purpose: Get the range of the rangewindow. This is how many
  475. // lines are displayed at one time
  476. // in the window the scroll bar is attached to.
  477. // This also controls the size of the slider, its size is proportional
  478. // to the number of lines displayed / total number of lines.
  479. //-----------------------------------------------------------------------------
  480. int ScrollBar::GetRangeWindow()
  481. {
  482. return _slider->GetRangeWindow();
  483. }
  484. //-----------------------------------------------------------------------------
  485. // Purpose:
  486. //-----------------------------------------------------------------------------
  487. void ScrollBar::Validate()
  488. {
  489. if ( _slider != null )
  490. {
  491. int buttonOffset = 0;
  492. for( int i=0; i<2; i++ )
  493. {
  494. if( _button[i] != null )
  495. {
  496. if( _button[i]->IsVisible() )
  497. {
  498. if( _slider->IsVertical() )
  499. {
  500. buttonOffset += _button[i]->GetTall();
  501. }
  502. else
  503. {
  504. buttonOffset += _button[i]->GetWide();
  505. }
  506. }
  507. }
  508. }
  509. _slider->SetButtonOffset(buttonOffset);
  510. }
  511. }
  512. //-----------------------------------------------------------------------------
  513. // Purpose:
  514. //-----------------------------------------------------------------------------
  515. void ScrollBar::SetScrollbarButtonsVisible(bool visible)
  516. {
  517. for( int i=0; i<2; i++ )
  518. {
  519. if( _button[i] != null )
  520. {
  521. _button[i]->SetShouldPaint( visible );
  522. _button[i]->SetEnabled( visible );
  523. }
  524. }
  525. }
  526. //-----------------------------------------------------------------------------
  527. // Purpose:
  528. //-----------------------------------------------------------------------------
  529. void ScrollBar::UseImages( const char *pszUpArrow, const char *pszDownArrow, const char *pszLine, const char *pszBox )
  530. {
  531. if ( pszUpArrow )
  532. {
  533. if ( !m_pUpArrow )
  534. {
  535. m_pUpArrow = new vgui::ImagePanel( this, "UpArrow" );
  536. if ( m_pUpArrow )
  537. {
  538. m_pUpArrow->SetImage( pszUpArrow );
  539. m_pUpArrow->SetShouldScaleImage( true );
  540. m_pUpArrow->SetFgColor( Color( 255, 255, 255, 255 ) );
  541. m_pUpArrow->SetAlpha( 255 );
  542. m_pUpArrow->SetZPos( -1 );
  543. }
  544. }
  545. m_pUpArrow->SetImage( pszUpArrow );
  546. m_pUpArrow->SetRotation( IsVertical() ? ROTATED_UNROTATED : ROTATED_CLOCKWISE_90 );
  547. }
  548. else if ( m_pUpArrow )
  549. {
  550. m_pUpArrow->MarkForDeletion();
  551. m_pUpArrow = NULL;
  552. }
  553. if ( pszDownArrow )
  554. {
  555. if ( !m_pDownArrow )
  556. {
  557. m_pDownArrow = new vgui::ImagePanel( this, "DownArrow" );
  558. if ( m_pDownArrow )
  559. {
  560. m_pDownArrow->SetShouldScaleImage( true );
  561. m_pDownArrow->SetFgColor( Color( 255, 255, 255, 255 ) );
  562. m_pDownArrow->SetAlpha( 255 );
  563. m_pDownArrow->SetZPos( -1 );
  564. }
  565. }
  566. m_pDownArrow->SetImage( pszDownArrow );
  567. m_pDownArrow->SetRotation( IsVertical() ? ROTATED_UNROTATED : ROTATED_CLOCKWISE_90 );
  568. }
  569. else if ( m_pDownArrow )
  570. {
  571. m_pDownArrow->MarkForDeletion();
  572. m_pDownArrow = NULL;
  573. }
  574. if ( pszLine )
  575. {
  576. if ( !m_pLine )
  577. {
  578. m_pLine = new ImagePanel( this, "Line" );
  579. if ( m_pLine )
  580. {
  581. m_pLine->SetShouldScaleImage( true );
  582. m_pLine->SetZPos( -1 );
  583. }
  584. }
  585. m_pLine->SetImage( pszLine );
  586. m_pLine->SetRotation( IsVertical() ? ROTATED_UNROTATED : ROTATED_CLOCKWISE_90 );
  587. }
  588. else if ( m_pLine )
  589. {
  590. m_pLine->MarkForDeletion();
  591. m_pLine = NULL;
  592. }
  593. if ( pszBox )
  594. {
  595. if ( !m_pBox )
  596. {
  597. m_pBox = new ImagePanel( this, "Box" );
  598. if ( m_pBox )
  599. {
  600. m_pBox->SetShouldScaleImage( true );
  601. m_pBox->SetZPos( -1 );
  602. }
  603. }
  604. m_pBox->SetImage( pszBox );
  605. m_pBox->SetRotation( IsVertical() ? ROTATED_UNROTATED : ROTATED_CLOCKWISE_90 );
  606. }
  607. else if ( m_pBox )
  608. {
  609. m_pBox->MarkForDeletion();
  610. m_pBox = NULL;
  611. }
  612. UpdateButtonsForImages();
  613. InvalidateLayout();
  614. }
  615. //-----------------------------------------------------------------------------
  616. // Purpose:
  617. //-----------------------------------------------------------------------------
  618. void ScrollBar::UpdateButtonsForImages( void )
  619. {
  620. // Turn off parts of our drawing based on which images we're replacing it with
  621. if ( m_pUpArrow || m_pDownArrow )
  622. {
  623. SetScrollbarButtonsVisible( false );
  624. _button[0]->SetPaintBorderEnabled( false );
  625. _button[1]->SetPaintBorderEnabled( false );
  626. m_bAutoHideButtons = false;
  627. }
  628. if ( m_pLine || m_pBox )
  629. {
  630. SetPaintBackgroundEnabled( false );
  631. SetPaintBorderEnabled( false );
  632. if ( _slider )
  633. {
  634. _slider->SetPaintEnabled( false );
  635. }
  636. }
  637. }
  638. //-----------------------------------------------------------------------------
  639. // Purpose:
  640. //-----------------------------------------------------------------------------
  641. void ScrollBar::UpdateSliderImages( void )
  642. {
  643. if ( m_pUpArrow && m_pDownArrow )
  644. {
  645. // set the alpha on the up arrow
  646. int nMin, nMax;
  647. GetRange( nMin, nMax );
  648. int nScrollPos = GetValue();
  649. int nRangeWindow = GetRangeWindow();
  650. int nBottom = nMax - nRangeWindow;
  651. if ( nBottom < 0 )
  652. {
  653. nBottom = 0;
  654. }
  655. // set the alpha on the up arrow
  656. int nAlpha = ( nScrollPos - nMin <= 0 ) ? 90 : 255;
  657. m_pUpArrow->SetAlpha( nAlpha );
  658. // set the alpha on the down arrow
  659. nAlpha = ( nScrollPos >= nBottom ) ? 90 : 255;
  660. m_pDownArrow->SetAlpha( nAlpha );
  661. }
  662. if ( m_pLine && m_pBox )
  663. {
  664. ScrollBarSlider *pSlider = GetSlider();
  665. if ( pSlider && pSlider->GetRangeWindow() > 0 )
  666. {
  667. int x, y, w, t, min, max;
  668. m_pLine->GetBounds( x, y, w, t );
  669. // If our slider needs layout, force it to do it now
  670. if ( pSlider->IsLayoutInvalid() )
  671. {
  672. pSlider->InvalidateLayout( true );
  673. }
  674. pSlider->GetNobPos( min, max );
  675. if ( IsVertical() )
  676. {
  677. m_pBox->SetBounds( x, y + min, w, ( max - min ) );
  678. }
  679. else
  680. {
  681. m_pBox->SetBounds( x + min, 0, (max-min), t );
  682. }
  683. }
  684. }
  685. }
  686. void ScrollBar::ApplySettings( KeyValues *pInResourceData )
  687. {
  688. BaseClass::ApplySettings( pInResourceData );
  689. m_bNoButtons = pInResourceData->GetBool( "nobuttons", false );
  690. KeyValues *pSliderKV = pInResourceData->FindKey( "Slider" );
  691. if ( pSliderKV && _slider )
  692. {
  693. _slider->ApplySettings( pSliderKV );
  694. }
  695. KeyValues *pDownButtonKV = pInResourceData->FindKey( "DownButton" );
  696. if ( pDownButtonKV && _button[0] )
  697. {
  698. _button[0]->ApplySettings( pDownButtonKV );
  699. }
  700. KeyValues *pUpButtonKV = pInResourceData->FindKey( "UpButton" );
  701. if ( pUpButtonKV && _button[0] )
  702. {
  703. _button[1]->ApplySettings( pUpButtonKV );
  704. }
  705. }