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.

137 lines
2.8 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxSlider.cpp
  5. // implementation: Win32 API
  6. // last modified: Mar 18 1999, Mete Ciragan
  7. // copyright: The programs and associated files contained in this
  8. // distribution were developed by Mete Ciragan. The programs
  9. // are not in the public domain, but they are freely
  10. // distributable without licensing fees. These programs are
  11. // provided without guarantee or warrantee expressed or
  12. // implied.
  13. //
  14. #include "mxtk/mxSlider.h"
  15. #include <windows.h>
  16. #include <commctrl.h>
  17. class mxSlider_i
  18. {
  19. public:
  20. int dummy;
  21. };
  22. mxSlider::mxSlider (mxWindow *parent, int x, int y, int w, int h, int id, int style)
  23. : mxWidget (parent, x, y, w, h)
  24. {
  25. if (!parent)
  26. return;
  27. DWORD dwStyle = WS_CHILD | WS_VISIBLE;
  28. HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle ();
  29. if (style == Horizontal)
  30. dwStyle = WS_CHILD | WS_VISIBLE | TBS_HORZ;
  31. else if (style == Vertical)
  32. dwStyle = WS_CHILD | WS_VISIBLE | TBS_VERT;
  33. void *handle = (void *) CreateWindowEx (0, TRACKBAR_CLASS, "", dwStyle,
  34. x, y, w, h, hwndParent,
  35. (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL);
  36. SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0));
  37. SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this);
  38. setHandle (handle);
  39. setType (MX_SLIDER);
  40. setParent (parent);
  41. setId (id);
  42. }
  43. mxSlider::~mxSlider ()
  44. {
  45. }
  46. void
  47. mxSlider::setValue (float value)
  48. {
  49. int ivalue = (int)((((value - m_min) / (m_max - m_min)) * m_ticks) + 0.5);
  50. SendMessage ((HWND) getHandle (), TBM_SETPOS, (WPARAM) true, (LPARAM) ivalue);
  51. }
  52. void
  53. mxSlider::setRange (float min, float max, int ticks)
  54. {
  55. m_min = min;
  56. m_max = max;
  57. m_ticks = ticks;
  58. SendMessage ((HWND) getHandle (), TBM_SETRANGE, (WPARAM) true, (LPARAM) MAKELONG(0, ticks));
  59. }
  60. void
  61. mxSlider::setSteps (int line, int page)
  62. {
  63. SendMessage ((HWND) getHandle (), TBM_SETLINESIZE, 0, (LPARAM) line);
  64. SendMessage ((HWND) getHandle (), TBM_SETPAGESIZE, 0, (LPARAM) page);
  65. }
  66. float
  67. mxSlider::getValue () const
  68. {
  69. int ivalue = SendMessage ((HWND) getHandle (), TBM_GETPOS, 0, 0L);
  70. return (ivalue / (float)m_ticks) * (m_max - m_min) + m_min;
  71. }
  72. float
  73. mxSlider::getTrackValue ( int ivalue ) const
  74. {
  75. return (ivalue / (float)m_ticks) * (m_max - m_min) + m_min;
  76. }
  77. float
  78. mxSlider::getMinValue () const
  79. {
  80. return m_min;
  81. // return (int) SendMessage ((HWND) getHandle (), TBM_GETRANGEMIN, 0, 0L);
  82. }
  83. float
  84. mxSlider::getMaxValue () const
  85. {
  86. return m_max;
  87. // return (int) SendMessage ((HWND) getHandle (), TBM_GETRANGEMAX, 0, 0L);
  88. }
  89. int
  90. mxSlider::getLineStep () const
  91. {
  92. return (int) SendMessage ((HWND) getHandle (), TBM_GETLINESIZE, 0, 0L);
  93. }
  94. int
  95. mxSlider::getPageStep () const
  96. {
  97. return (int) SendMessage ((HWND) getHandle (), TBM_GETPAGESIZE, 0, 0L);
  98. }