Leaked source code of windows server 2003
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.

109 lines
1.9 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. stepper.cpp
  5. Abstract:
  6. Implements time keeping and display in the graph window.
  7. --*/
  8. #include "polyline.h"
  9. CStepper::CStepper()
  10. {
  11. m_iPos = 0;
  12. m_iStepNum = 0;
  13. m_iStepCnt = 1;
  14. }
  15. void CStepper::Init(INT iLength, INT iStepCnt)
  16. {
  17. m_iStepCnt = iStepCnt ? iStepCnt : 1;
  18. m_iStepSize = iLength / m_iStepCnt;
  19. m_iRemainder = iLength - m_iStepCnt * m_iStepSize;
  20. m_iState = m_iStepCnt;
  21. m_iPos = 0;
  22. m_iStepNum = 0;
  23. }
  24. void CStepper::Reset()
  25. {
  26. m_iPos = 0;
  27. m_iStepNum = 0;
  28. m_iState = m_iStepCnt;
  29. }
  30. INT CStepper::NextPosition()
  31. {
  32. m_iPos += m_iStepSize;
  33. m_iState -= m_iRemainder;
  34. if (m_iState <= 0)
  35. {
  36. m_iState += m_iStepCnt;
  37. m_iPos++;
  38. }
  39. m_iStepNum++;
  40. return m_iPos;
  41. }
  42. INT CStepper::PrevPosition()
  43. {
  44. m_iPos -= m_iStepSize;
  45. m_iState += m_iRemainder;
  46. if (m_iState > m_iStepCnt)
  47. {
  48. m_iState -= m_iStepCnt;
  49. m_iPos--;
  50. }
  51. m_iStepNum--;
  52. return m_iPos;
  53. }
  54. INT CStepper::StepTo(INT nSteps)
  55. {
  56. INT iDiff;
  57. iDiff = (nSteps * m_iRemainder) / m_iStepCnt;
  58. m_iState = (iDiff + 1) * m_iStepCnt - (nSteps * m_iRemainder);
  59. m_iPos = (nSteps * m_iStepSize) + iDiff;
  60. m_iStepNum = nSteps;
  61. return m_iPos;
  62. }
  63. INT CStepper::PrevStepNum( INT iPosition )
  64. {
  65. INT iStepNum = -1;
  66. INT iLength;
  67. // Floating point conversion to integer truncates,
  68. // so this method returns the step previous to the position.
  69. iLength = m_iStepCnt * m_iStepSize + m_iRemainder;
  70. if ( iPosition <= iLength ) {
  71. // Calculation is (iPosition/iLength) * m_iStepCnt.
  72. iStepNum = iPosition * m_iStepCnt;
  73. iStepNum = iStepNum / iLength;
  74. }
  75. return iStepNum;
  76. }