scrollbarctrl.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/scrollbarctrl.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/04/02 2:41p $*
  29. * *
  30. * $Revision:: 13 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
  36. #pragma warning(disable : 4530)
  37. #include "scrollbarctrl.h"
  38. #include "assetmgr.h"
  39. #include "refcount.h"
  40. #include "mousemgr.h"
  41. #include "ww3d.h"
  42. #include "dialogmgr.h"
  43. #include "dialogbase.h"
  44. #include "stylemgr.h"
  45. #include "texture.h"
  46. ////////////////////////////////////////////////////////////////
  47. // Local constants
  48. ////////////////////////////////////////////////////////////////
  49. /*
  50. static const RectClass TopBtnUpUVs (103, 94, 125, 116);
  51. static const RectClass TopBtnDnUVs (103, 70, 125, 92);
  52. static const RectClass BottomBtnUpUVs (79, 94, 101, 116);
  53. static const RectClass BottomBtnDnUVs (79, 70, 101, 92);
  54. static const RectClass ThumbDnUVs (150, 70, 171, 136);
  55. static const RectClass ThumbUpUVs (127, 70, 148, 136);
  56. */
  57. static const RectClass TopBtnUpUVs[2] =
  58. {
  59. RectClass (100, 212, 121, 234),
  60. RectClass (147, 228, 169, 241)
  61. };
  62. static const RectClass TopBtnDnUVs[2] =
  63. {
  64. RectClass (76, 212, 98, 234),
  65. RectClass (147, 213, 169, 226)
  66. };
  67. static const RectClass BottomBtnUpUVs[2] =
  68. {
  69. RectClass (52, 212, 74, 234),
  70. RectClass (123, 228, 145, 241)
  71. };
  72. static const RectClass BottomBtnDnUVs[2] =
  73. {
  74. RectClass (28, 212, 50, 234),
  75. RectClass (123, 213, 145, 226)
  76. };
  77. static const RectClass ThumbDnUVs[2] =
  78. {
  79. RectClass (233, 138, 254, 204),
  80. RectClass (171, 213, 193, 222)
  81. };
  82. static const RectClass ThumbUpUVs[2] =
  83. {
  84. RectClass (233, 70, 254, 136),
  85. RectClass (171, 224, 193, 233)
  86. };
  87. static const float DEFAULT_WIDTH = 10;
  88. static const float BUTTON_V_OFFSET = 10;
  89. ////////////////////////////////////////////////////////////////
  90. //
  91. // ScrollBarCtrlClass
  92. //
  93. ////////////////////////////////////////////////////////////////
  94. ScrollBarCtrlClass::ScrollBarCtrlClass (void) :
  95. CurrState (NORMAL),
  96. MinPos (0),
  97. MaxPos (100),
  98. CurrPos (0),
  99. PageSize (10),
  100. ThumbWidth (0),
  101. ThumbHeight (0),
  102. ThumbRect (0, 0, 0, 0),
  103. WasButtonPressedOnMe (false),
  104. TrackRect (0, 0, 0, 0),
  105. TopButtonRect (0, 0, 0, 0),
  106. BottomButtonRect (0, 0, 0, 0),
  107. IsDragging (false),
  108. WasTopButtonPressed (false),
  109. WasBottomButtonPressed (false),
  110. Width (DEFAULT_WIDTH),
  111. ScaleX (1.0F),
  112. ScaleY (1.0F),
  113. MouseClickPos (0, 0),
  114. MouseClickSliderPos (0),
  115. IsSmallBMPMode (false)
  116. {
  117. //
  118. // Configure the renderers
  119. //
  120. StyleMgrClass::Configure_Renderer (&ButtonRenderer);
  121. StyleMgrClass::Configure_Renderer (&ControlRenderers[0]);
  122. StyleMgrClass::Configure_Renderer (&ControlRenderers[1]);
  123. //
  124. // Load the texture for the control
  125. //
  126. TextureClass *texture = WW3DAssetManager::Get_Instance ()->Get_Texture ("IF_MENUPARTS9.TGA", TextureClass::MIP_LEVELS_1);
  127. ButtonRenderer.Set_Texture (texture);
  128. REF_PTR_RELEASE (texture);
  129. //
  130. // Scale the control
  131. //
  132. ScaleX = Render2DClass::Get_Screen_Resolution().Width () / 800;
  133. ScaleY = Render2DClass::Get_Screen_Resolution().Height () / 600;
  134. Width = Width * ScaleX;
  135. return ;
  136. }
  137. ////////////////////////////////////////////////////////////////
  138. //
  139. // ~ScrollBarCtrlClass
  140. //
  141. ////////////////////////////////////////////////////////////////
  142. ScrollBarCtrlClass::~ScrollBarCtrlClass (void)
  143. {
  144. return ;
  145. }
  146. ////////////////////////////////////////////////////////////////
  147. //
  148. // Create_Button_Renderer
  149. //
  150. ////////////////////////////////////////////////////////////////
  151. void
  152. ScrollBarCtrlClass::Create_Button_Renderer (void)
  153. {
  154. ButtonRenderer.Reset ();
  155. //
  156. // Determine what UVs to use for the thumb
  157. //
  158. RectClass thumb_uvs = ThumbUpUVs[IsSmallBMPMode];
  159. if (IsDragging) {
  160. thumb_uvs = ThumbDnUVs[IsSmallBMPMode];
  161. }
  162. thumb_uvs.Inverse_Scale (Vector2 (255, 255));
  163. //
  164. // Flip the thumb if its past the halfway mark
  165. //
  166. if (IsSmallBMPMode && ThumbRect.Top > (ClientRect.Top + ClientRect.Height () / 2)) {
  167. float temp = thumb_uvs.Top;
  168. thumb_uvs.Top = thumb_uvs.Bottom;
  169. thumb_uvs.Bottom = temp;
  170. }
  171. //
  172. // Draw the thumb
  173. //
  174. ButtonRenderer.Add_Quad (ThumbRect, thumb_uvs);
  175. //
  176. // Determine which UVs to use for the buttons
  177. //
  178. RectClass bottom_btn_uvs = BottomBtnUpUVs[IsSmallBMPMode];
  179. RectClass top_btn_uvs = TopBtnUpUVs[IsSmallBMPMode];
  180. //
  181. // Use the "button-down" UVs if necessary
  182. //
  183. if (WasTopButtonPressed) {
  184. top_btn_uvs = TopBtnDnUVs[IsSmallBMPMode];
  185. } else if (WasBottomButtonPressed) {
  186. bottom_btn_uvs = BottomBtnDnUVs[IsSmallBMPMode];
  187. }
  188. //
  189. // Normalize the UVs
  190. //
  191. top_btn_uvs.Inverse_Scale (Vector2 (255, 255));
  192. bottom_btn_uvs.Inverse_Scale (Vector2 (255, 255));
  193. //
  194. // Draw the buttons
  195. //
  196. ButtonRenderer.Add_Quad (TopButtonRect, top_btn_uvs);
  197. ButtonRenderer.Add_Quad (BottomButtonRect, bottom_btn_uvs);
  198. return ;
  199. }
  200. ////////////////////////////////////////////////////////////////
  201. //
  202. // Create_Control_Renderers
  203. //
  204. ////////////////////////////////////////////////////////////////
  205. void
  206. ScrollBarCtrlClass::Create_Control_Renderers (void)
  207. {
  208. //
  209. // Create a renderer for each state
  210. //
  211. for (int index = 0; index < STATE_MAX; index ++) {
  212. Render2DClass &renderer = ControlRenderers[index];
  213. //
  214. // Configure this renderer
  215. //
  216. renderer.Reset ();
  217. renderer.Enable_Texturing (false);
  218. //
  219. // Determine which color to draw the outline in
  220. //
  221. int color = StyleMgrClass::Get_Line_Color ();
  222. int bkcolor = StyleMgrClass::Get_Bk_Color ();
  223. if (index == DISABLED) {
  224. color = StyleMgrClass::Get_Disabled_Line_Color ();
  225. bkcolor = StyleMgrClass::Get_Disabled_Bk_Color ();
  226. }
  227. //
  228. // Draw the bounding rectangle for the control
  229. //
  230. RectClass outline_rect = Rect;
  231. outline_rect.Top = TopButtonRect.Bottom - (TopButtonRect.Height () / 2);
  232. outline_rect.Bottom = BottomButtonRect.Top + (BottomButtonRect.Height () / 2);
  233. renderer.Add_Outline (outline_rect, 1.0F, color);
  234. //
  235. // Compose two "gradient" rectangles
  236. //
  237. RectClass top_rect;
  238. top_rect.Left = ClientRect.Left;
  239. top_rect.Right = ClientRect.Right;
  240. top_rect.Top = outline_rect.Top;
  241. top_rect.Bottom = ThumbRect.Top;
  242. RectClass bottom_rect;
  243. bottom_rect.Left = ClientRect.Left;
  244. bottom_rect.Right = ClientRect.Right;
  245. bottom_rect.Top = ThumbRect.Bottom;
  246. bottom_rect.Bottom = outline_rect.Bottom;
  247. int color_in = (color & 0x00FFFFFF) | RGBA_TO_INT32 (0, 0, 0, 255);
  248. int color_out = (color & 0x00FFFFFF) | RGBA_TO_INT32 (0, 0, 0, 10);
  249. //
  250. // Draw the gradients
  251. //
  252. renderer.Add_Quad_VGradient (top_rect, color_in, color_out);
  253. renderer.Add_Quad_VGradient (bottom_rect, color_out, color_in);
  254. }
  255. return ;
  256. }
  257. ////////////////////////////////////////////////////////////////
  258. //
  259. // On_Set_Cursor
  260. //
  261. ////////////////////////////////////////////////////////////////
  262. void
  263. ScrollBarCtrlClass::On_Set_Cursor (const Vector2 &mouse_pos)
  264. {
  265. //
  266. // Change the mouse cursor
  267. //
  268. MouseMgrClass::Set_Cursor (MouseMgrClass::CURSOR_ACTION);
  269. return ;
  270. }
  271. ////////////////////////////////////////////////////////////////
  272. //
  273. // Update_Client_Rect
  274. //
  275. ////////////////////////////////////////////////////////////////
  276. void
  277. ScrollBarCtrlClass::Update_Client_Rect (void)
  278. {
  279. //
  280. // Snap the rect to the alloted size
  281. //
  282. if (Rect.Right >= 0.0f) {
  283. Rect.Left = int(Rect.Right - Width);
  284. } else {
  285. Rect.Right = (Rect.Left + Width);
  286. }
  287. //
  288. // Set the client area
  289. //
  290. ClientRect = Rect;
  291. //
  292. // Scale the thumb dimensions
  293. //
  294. ThumbWidth = (int)(ThumbUpUVs[IsSmallBMPMode].Width () * ScaleX);
  295. ThumbHeight = (int)(ThumbUpUVs[IsSmallBMPMode].Height () * ScaleY);
  296. //
  297. // Scale the button dimensions
  298. //
  299. int button_width = (int)(TopBtnUpUVs[IsSmallBMPMode].Width () * ScaleX);
  300. int button_height = (int)(TopBtnUpUVs[IsSmallBMPMode].Height () * ScaleY);
  301. //
  302. // Update the top button's bounding rectangle
  303. //
  304. TopButtonRect.Left = int(ClientRect.Left + (ClientRect.Width () / 2) - (button_width / 2));
  305. TopButtonRect.Top = int(ClientRect.Top - (BUTTON_V_OFFSET * ScaleY));
  306. TopButtonRect.Right = int(TopButtonRect.Left + button_width);
  307. TopButtonRect.Bottom = int(TopButtonRect.Top + button_height);
  308. //
  309. // Update the bottom button's bounding rectangle
  310. //
  311. BottomButtonRect.Left = int(ClientRect.Left + (ClientRect.Width () / 2) - (button_width / 2));
  312. BottomButtonRect.Top = int(ClientRect.Bottom - button_height + (BUTTON_V_OFFSET * ScaleY));
  313. BottomButtonRect.Right = int(BottomButtonRect.Left + button_width);
  314. BottomButtonRect.Bottom = int(BottomButtonRect.Top + button_height);
  315. //
  316. // Adjust the rectangle to include the top and bottom buttons
  317. //
  318. Rect.Top = TopButtonRect.Top;
  319. Rect.Bottom = BottomButtonRect.Bottom;
  320. //
  321. // Update the track rectangle so it doesn't extend into the buttons
  322. //
  323. TrackRect = ClientRect;
  324. TrackRect.Top = TopButtonRect.Bottom;
  325. TrackRect.Bottom = BottomButtonRect.Top - ThumbHeight;
  326. //
  327. // Update the bounding box of the thumb
  328. //
  329. Update_Thumb_Rect ();
  330. //
  331. // Force a repaint
  332. //
  333. Set_Dirty ();
  334. return ;
  335. }
  336. ////////////////////////////////////////////////////////////////
  337. //
  338. // Render
  339. //
  340. ////////////////////////////////////////////////////////////////
  341. void
  342. ScrollBarCtrlClass::Render (void)
  343. {
  344. //
  345. // Handle scrolling (if necessary)
  346. //
  347. if (WasTopButtonPressed) {
  348. Set_Pos (CurrPos - 1);
  349. } else if (WasBottomButtonPressed) {
  350. Set_Pos (CurrPos + 1);
  351. }
  352. //
  353. // Recreate the renderers (if necessary)
  354. //
  355. if (IsDirty) {
  356. Create_Control_Renderers ();
  357. Create_Button_Renderer ();
  358. }
  359. //
  360. // Render the background and text for the current state
  361. //
  362. ControlRenderers[CurrState].Render ();
  363. ButtonRenderer.Render ();
  364. DialogControlClass::Render ();
  365. return ;
  366. }
  367. ////////////////////////////////////////////////////////////////
  368. //
  369. // On_LButton_Down
  370. //
  371. ////////////////////////////////////////////////////////////////
  372. void
  373. ScrollBarCtrlClass::On_LButton_Down (const Vector2 &mouse_pos)
  374. {
  375. Set_Capture ();
  376. //
  377. // Check to see if the user clicked on either of the buttons
  378. //
  379. if (TopButtonRect.Contains (mouse_pos)) {
  380. WasTopButtonPressed = true;
  381. } else if (BottomButtonRect.Contains (mouse_pos)) {
  382. WasBottomButtonPressed = true;
  383. } else {
  384. //
  385. // Did the user click on the thumb?
  386. //
  387. if (ThumbRect.Contains (mouse_pos)) {
  388. IsDragging = true;
  389. } else if (mouse_pos.Y < ThumbRect.Top) {
  390. //
  391. // Page Up
  392. //
  393. Scroll_Page (-1);
  394. } else if (mouse_pos.Y > ThumbRect.Bottom) {
  395. //
  396. // Page Down
  397. //
  398. Scroll_Page (1);
  399. }
  400. }
  401. MouseClickPos = mouse_pos;
  402. MouseClickSliderPos = ThumbRect.Top;
  403. WasButtonPressedOnMe = true;
  404. Set_Dirty ();
  405. return ;
  406. }
  407. ////////////////////////////////////////////////////////////////
  408. //
  409. // On_LButton_Up
  410. //
  411. ////////////////////////////////////////////////////////////////
  412. void
  413. ScrollBarCtrlClass::On_LButton_Up (const Vector2 &mouse_pos)
  414. {
  415. Release_Capture ();
  416. WasButtonPressedOnMe = false;
  417. IsDragging = false;
  418. WasTopButtonPressed = false;
  419. WasBottomButtonPressed = false;
  420. Set_Dirty ();
  421. return ;
  422. }
  423. ////////////////////////////////////////////////////////////////
  424. //
  425. // On_Mouse_Move
  426. //
  427. ////////////////////////////////////////////////////////////////
  428. void
  429. ScrollBarCtrlClass::On_Mouse_Move (const Vector2 &mouse_pos)
  430. {
  431. //
  432. // Update the thumb position
  433. //
  434. if (IsDragging) {
  435. //
  436. // Calculate a new position from the change in mouse position
  437. //
  438. float y_delta = (mouse_pos.Y - MouseClickPos.Y);
  439. float percent = ((MouseClickSliderPos + y_delta) - TrackRect.Top) / TrackRect.Height ();
  440. int new_pos = MinPos + int(percent * (MaxPos - MinPos));
  441. //
  442. // Set the new position
  443. //
  444. Set_Pos (new_pos);
  445. }
  446. return ;
  447. }
  448. ////////////////////////////////////////////////////////////////
  449. //
  450. // On_Set_Focus
  451. //
  452. ////////////////////////////////////////////////////////////////
  453. void
  454. ScrollBarCtrlClass::On_Set_Focus (void)
  455. {
  456. //
  457. // Force a repaint
  458. //
  459. Set_Dirty ();
  460. DialogControlClass::On_Set_Focus ();
  461. return ;
  462. }
  463. ////////////////////////////////////////////////////////////////
  464. //
  465. // On_Kill_Focus
  466. //
  467. ////////////////////////////////////////////////////////////////
  468. void
  469. ScrollBarCtrlClass::On_Kill_Focus (DialogControlClass *focus)
  470. {
  471. IsDragging = false;
  472. WasTopButtonPressed = false;
  473. WasBottomButtonPressed = false;
  474. //
  475. // Force a repaint
  476. //
  477. Set_Dirty ();
  478. DialogControlClass::On_Kill_Focus (focus);
  479. return ;
  480. }
  481. ////////////////////////////////////////////////////////////////
  482. //
  483. // On_Key_Down
  484. //
  485. ////////////////////////////////////////////////////////////////
  486. bool
  487. ScrollBarCtrlClass::On_Key_Down (uint32 key_id, uint32 key_data)
  488. {
  489. bool handled = true;
  490. switch (key_id)
  491. {
  492. case VK_UP:
  493. case VK_LEFT:
  494. Set_Pos (CurrPos - 1);
  495. break;
  496. case VK_DOWN:
  497. case VK_RIGHT:
  498. Set_Pos (CurrPos + 1);
  499. break;
  500. case VK_HOME:
  501. Set_Pos (MinPos);
  502. break;
  503. case VK_END:
  504. Set_Pos (MaxPos);
  505. break;
  506. //
  507. // Page up
  508. //
  509. case VK_PRIOR:
  510. Scroll_Page (-1);
  511. break;
  512. //
  513. // Page down
  514. //
  515. case VK_NEXT:
  516. Scroll_Page (1);
  517. break;
  518. default:
  519. handled = false;
  520. break;
  521. }
  522. return handled;
  523. }
  524. ////////////////////////////////////////////////////////////////
  525. //
  526. // On_Create
  527. //
  528. ////////////////////////////////////////////////////////////////
  529. void
  530. ScrollBarCtrlClass::On_Create (void)
  531. {
  532. return ;
  533. }
  534. ////////////////////////////////////////////////////////////////
  535. //
  536. // Slider_Pos_From_Mouse_Pos
  537. //
  538. ////////////////////////////////////////////////////////////////
  539. int
  540. ScrollBarCtrlClass::Slider_Pos_From_Mouse_Pos (const Vector2 &mouse_pos)
  541. {
  542. int retval = 0;
  543. if (mouse_pos.Y < TrackRect.Top) {
  544. //
  545. // Mouse is above the track area of the control
  546. //
  547. retval = 0;
  548. } else if (mouse_pos.Y >= TrackRect.Bottom) {
  549. //
  550. // Mouse is below the track areaa of the control
  551. //
  552. retval = MaxPos;
  553. } else {
  554. //
  555. // Calculate where in the range the mouse is and return its position
  556. //
  557. float percent = (mouse_pos.Y - TrackRect.Top) / TrackRect.Height ();
  558. retval = MinPos + int(percent * (MaxPos - MinPos));
  559. }
  560. return retval;
  561. }
  562. ////////////////////////////////////////////////////////////////
  563. //
  564. // Set_Range
  565. //
  566. ////////////////////////////////////////////////////////////////
  567. void
  568. ScrollBarCtrlClass::Set_Range (int range_min, int range_max)
  569. {
  570. /*if (MinPos != range_min) {
  571. Set_Pos (range_min);
  572. }*/
  573. MinPos = range_min;
  574. MaxPos = max (range_min, range_max);
  575. Update_Thumb_Rect ();
  576. Set_Dirty ();
  577. return ;
  578. }
  579. ////////////////////////////////////////////////////////////////
  580. //
  581. // Scroll_Page
  582. //
  583. ////////////////////////////////////////////////////////////////
  584. void
  585. ScrollBarCtrlClass::Scroll_Page (int direction, bool send_notify)
  586. {
  587. //
  588. // Calculate a page scroll (if using uniform page sizes)
  589. //
  590. int pos = CurrPos + (direction * PageSize);
  591. Set_Pos (pos, send_notify);
  592. //
  593. // Notify the advise sinks that the page has been scrolled
  594. //
  595. if (send_notify) {
  596. ADVISE_NOTIFY (On_VScroll_Page (this, Get_ID (), direction));
  597. }
  598. return ;
  599. }
  600. ////////////////////////////////////////////////////////////////
  601. //
  602. // Set_Pos
  603. //
  604. ////////////////////////////////////////////////////////////////
  605. void
  606. ScrollBarCtrlClass::Set_Pos (int pos, bool send_notify)
  607. {
  608. //
  609. // Bound the new position
  610. //
  611. if (pos < MinPos) {
  612. pos = MinPos;
  613. } else if (pos > MaxPos) {
  614. pos = MaxPos;
  615. }
  616. //
  617. // Update the current position
  618. //
  619. if (pos != CurrPos) {
  620. CurrPos = pos;
  621. //
  622. // Update the thumb's drag rectangle
  623. //
  624. Update_Thumb_Rect ();
  625. Set_Dirty ();
  626. //
  627. // Notify the advise sink(s)
  628. //
  629. if (send_notify) {
  630. if (Parent != NULL) {
  631. Parent->On_VScroll (this, Get_ID (), CurrPos);
  632. }
  633. if (AdviseSink != NULL) {
  634. AdviseSink->On_VScroll (this, Get_ID (), CurrPos);
  635. }
  636. }
  637. }
  638. return ;
  639. }
  640. ////////////////////////////////////////////////////////////////
  641. //
  642. // Update_Thumb_Rect
  643. //
  644. ////////////////////////////////////////////////////////////////
  645. void
  646. ScrollBarCtrlClass::Update_Thumb_Rect (void)
  647. {
  648. //
  649. // Recalculate the thumb position
  650. //
  651. float percent = float(CurrPos - MinPos) / float(MaxPos - MinPos);
  652. //
  653. // Build the rectangle from the thumb's position
  654. //
  655. if (IsSmallBMPMode) {
  656. ThumbRect.Left = int(ClientRect.Left + (ClientRect.Width () / 2) - (ThumbWidth / 2));
  657. ThumbRect.Right = int(ThumbRect.Left + ThumbWidth);
  658. } else {
  659. ThumbRect.Right = ClientRect.Right - 1;
  660. ThumbRect.Left = ThumbRect.Right - ThumbWidth;
  661. }
  662. ThumbRect.Top = int(TopButtonRect.Bottom + (TrackRect.Height () * percent));
  663. ThumbRect.Bottom = int(ThumbRect.Top + ThumbHeight);
  664. return ;
  665. }