Audio plugin host https://kx.studio/carla
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.

Fl_Osc_TSlider.cpp 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <cmath>
  2. #include "Fl_Osc_TSlider.H"
  3. //Copyright (c) 2015 Christopher Oliver
  4. //License: GNU GPL version 2 or later
  5. Fl_Osc_TSlider::Fl_Osc_TSlider(int x, int y, int w, int h, const char *label)
  6. :Fl_Osc_Slider(x, y, w, h, label), value_offset(0.0), value_scale(1.0)
  7. {
  8. Fl_Group *save = Fl_Group::current();
  9. tipwin = new TipWin();
  10. tipwin->hide();
  11. Fl_Group::current(save);
  12. tipwin->setRounding();
  13. }
  14. Fl_Osc_TSlider::~Fl_Osc_TSlider()
  15. {
  16. if (tipwin)
  17. delete tipwin;
  18. }
  19. void Fl_Osc_TSlider::setRounding(unsigned int digits)
  20. {
  21. tipwin->setRounding(digits);
  22. }
  23. int Fl_Osc_TSlider::handle(int event)
  24. {
  25. int super = 1;
  26. super = Fl_Osc_Slider::handle(event);
  27. switch(event) {
  28. case FL_PUSH:
  29. case FL_MOUSEWHEEL:
  30. if (!Fl::event_inside(x(),y(),w(),h()))
  31. return(1);
  32. tipwin->position(Fl::event_x_root()-Fl::event_x()+x(),
  33. Fl::event_y_root()-Fl::event_y()+h()+y()+5);
  34. case FL_DRAG:
  35. tipwin->showValue(transform(value()));
  36. break;
  37. case FL_RELEASE:
  38. case FL_HIDE:
  39. case FL_LEAVE:
  40. if (tipwin)
  41. tipwin->hide();
  42. return 1;
  43. }
  44. return super;
  45. }
  46. void Fl_Osc_TSlider::setTransform(float scale, float offset)
  47. {
  48. value_offset = offset;
  49. value_scale = scale;
  50. }
  51. float Fl_Osc_TSlider::transform(float x)
  52. {
  53. return value_scale * x + value_offset;
  54. }