gcsx_slider.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* GCSx
  2. ** SLIDER.H
  3. **
  4. ** Numerical slider widget
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #ifndef __GCSx_SLIDER_H_
  24. #define __GCSx_SLIDER_H_
  25. class WSlider : public Widget {
  26. protected:
  27. // Range and pixel length of slider
  28. int pixelLength;
  29. int rangeBegin;
  30. int rangeEnd;
  31. // Exact current value
  32. int currentValue;
  33. // Pixel position based on current value
  34. int pixelValue;
  35. // Currently dragging slider?
  36. int dragging;
  37. int draggingX;
  38. int draggingValue;
  39. // Linked?
  40. WNumberBox* linkedTo;
  41. enum {
  42. // Height and width of slider itself
  43. GUI_SLIDER_TABWIDTH = 10,
  44. GUI_SLIDER_TABHEIGHT = 20,
  45. // Height of slider track
  46. GUI_SLIDER_TRACKSIZE = 2,
  47. // Default length of slider track if not given
  48. GUI_SLIDER_TRACKLENGTH = 50,
  49. };
  50. public:
  51. // Actual length may differ slightly from length given
  52. WSlider(int sId, int sBegin, int sEnd, int* sSetting, int sLength = -1);
  53. // Optionally link a slider to a numberbox, which should have the same range
  54. void linkTo(WNumberBox* linked);
  55. int event(int hasFocus, const SDL_Event* event);
  56. void load();
  57. void apply();
  58. void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
  59. // Handles linkTo()
  60. virtual void siblingModified(Widget* modified);
  61. // Set or retrieve state
  62. int state() const;
  63. // ALL changes go through this function
  64. // 'fromLoad' is for internal use only
  65. int state(int newValue);
  66. int stateFromLoad(int newValue);
  67. // Set state based on a pixel location from 0 to pixelValue, inclusive
  68. // Returns actual state() value set (not the pixel value)
  69. int statePixel(int newPixel);
  70. };
  71. #endif