Counter Strike : Global Offensive Source Code
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.

785 lines
21 KiB

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