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.

37 lines
837B

  1. #include "VuMeter.hpp"
  2. #include <cmath>
  3. VuMeter::VuMeter(rack::Vec const& pos, rack::Vec const& size) :
  4. m_currentValue(0.f)
  5. {
  6. box.pos = pos;
  7. box.size = size;
  8. }
  9. void VuMeter::setValue(float cv)
  10. {
  11. m_currentValue = std::abs(cv / 10.f);
  12. if (m_currentValue < std::numeric_limits<float>::epsilon())
  13. m_currentValue = 0.f;
  14. else if (m_currentValue > 1.f)
  15. m_currentValue = 1.f;
  16. }
  17. void VuMeter::draw(NVGcontext* vg)
  18. {
  19. nvgSave(vg);
  20. nvgFillColor(vg, nvgRGBA(0x30, 0x33, 0x32, 0xFF));
  21. nvgBeginPath(vg);
  22. nvgRoundedRect(vg, 0.f, 0.f, box.size.x, box.size.y, 2.5f);
  23. nvgFill(vg);
  24. if (m_currentValue > 0.02f)
  25. {
  26. nvgBeginPath(vg);
  27. nvgFillColor(vg, nvgRGBA(0x0, 0x80, 0x0, 0xFF));
  28. nvgRoundedRect(vg, 0.f, box.size.y - box.size.y * m_currentValue, box.size.x, box.size.y * m_currentValue, 2.5f);
  29. nvgFill(vg);
  30. }
  31. nvgRestore(vg);
  32. }