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.

62 lines
1.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of Tal-Reverb by Patrick Kunz.
  4. Copyright(c) 2005-2010 Patrick Kunz, TAL
  5. Togu Audio Line, Inc.
  6. http://kunz.corrupt.ch
  7. This file may be licensed under the terms of of the
  8. GNU General Public License Version 2 (the ``GPL'').
  9. Software distributed under the License is distributed
  10. on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
  11. express or implied. See the GPL for the specific language
  12. governing rights and limitations.
  13. You should have received a copy of the GPL along with this
  14. program. If not, go to http://www.gnu.org/licenses/gpl.html
  15. or write to the Free Software Foundation, Inc.,
  16. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. ==============================================================================
  18. */
  19. class FilmStripKnob : public Slider
  20. {
  21. public:
  22. FilmStripKnob(Image image, const int numFrames, const bool stripIsHorizontal, int index)
  23. : Slider(juce::String(index)),
  24. filmStrip(image),
  25. numFrames_(numFrames),
  26. isHorizontal_(stripIsHorizontal)
  27. {
  28. setTextBoxStyle(NoTextBox, 0, 0, 0);
  29. setSliderStyle(RotaryVerticalDrag);
  30. frameHeight = filmStrip.getHeight() / numFrames_;
  31. frameWidth = filmStrip.getWidth();
  32. setRange(0.0f, 1.0f, 0.001f);
  33. getProperties().set(Identifier("index"), index);
  34. }
  35. void paint(Graphics& g) override
  36. {
  37. int value = (int)((getValue() - getMinimum()) / (getMaximum() - getMinimum()) * (numFrames_ - 1));
  38. if(isHorizontal_)
  39. {
  40. g.drawImage(filmStrip, 0, 0, getWidth(), getHeight(),
  41. value * frameWidth, 0, frameWidth, frameHeight);
  42. }
  43. else
  44. {
  45. g.drawImage(filmStrip, 0, 0, getWidth(), getHeight(),
  46. 0, value * frameHeight, frameWidth, frameHeight);
  47. }
  48. }
  49. private:
  50. Image filmStrip;
  51. const int numFrames_;
  52. const bool isHorizontal_;
  53. int frameWidth, frameHeight;
  54. };