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.

88 lines
2.3KB

  1. #include "rack.hpp"
  2. #include "BufferedDrawFunction.hpp"
  3. template <int H>
  4. struct GraduatedFader : SVGFader
  5. {
  6. int slider_height = 41;
  7. int slider_width = 20;
  8. int widget_width = 28;
  9. FramebufferWidget *notches;
  10. GraduatedFader()
  11. {
  12. background->svg = NULL;
  13. background->wrap();
  14. background->box.pos = Vec( 0, 0 );
  15. handle->svg = SVG::load( assetPlugin( plugin, "res/BaconSliderHandle.svg" ) );
  16. handle->wrap();
  17. maxHandlePos = Vec( (widget_width-slider_width)/2, 0 );
  18. minHandlePos = Vec( (widget_width-slider_width)/2, (H-slider_height) );
  19. box.size = Vec( widget_width, H );
  20. notches = new BufferedDrawFunctionWidget<GraduatedFader<H>>( Vec( 0, 0 ), box.size, this,
  21. &GraduatedFader<H>::drawBackground );
  22. }
  23. void draw( NVGcontext *vg ) override
  24. {
  25. notches->draw( vg );
  26. SVGFader::draw( vg );
  27. }
  28. void drawBackground( NVGcontext *vg )
  29. {
  30. int nStrokes = 10;
  31. int slideTop = slider_height / 2;
  32. int slideHeight = H - slider_height;
  33. int slideBump = 5;
  34. int slotWidth = 1;
  35. #ifdef DEBUG_NOTCHES
  36. nvgBeginPath( vg );
  37. nvgRect( vg, 0, 0, widget_width, H );
  38. nvgFillColor( vg, COLOR_RED );
  39. nvgFill( vg );
  40. #endif
  41. float dx = (1.0 * slideHeight) / nStrokes;
  42. // Firest the gray highlights
  43. for( int i=0; i<= nStrokes; ++i )
  44. {
  45. nvgBeginPath( vg );
  46. nvgRect( vg, 1, slideTop + dx * i, widget_width-2, 1 );
  47. nvgFillColor( vg, nvgRGBA( 200, 200, 200, 255 ) );
  48. nvgFill( vg );
  49. }
  50. // and now the black notches
  51. for( int i=0; i<= nStrokes; ++i )
  52. {
  53. nvgBeginPath( vg );
  54. nvgRect( vg, 1, slideTop + dx * i-1, widget_width-2, 1.5 );
  55. nvgFillColor( vg, nvgRGBA( 100, 100, 100, 255 ));
  56. nvgFill( vg );
  57. }
  58. // OK so now we want to draw the vertical line
  59. nvgBeginPath( vg );
  60. nvgRect( vg, widget_width/2 - slotWidth, slideTop - slideBump, 2 * slotWidth + 1, slideHeight + 2 * slideBump );
  61. nvgFillColor( vg, COLOR_BLACK );
  62. nvgFill( vg );
  63. }
  64. void onZoom( EventZoom &e ) override
  65. {
  66. // Need this because I don't add it as a child, since the base class does something funky with that
  67. notches->onZoom( e );
  68. SVGFader::onZoom( e );
  69. }
  70. };